{"action":"created","issue":{"url":"https://api.github.com/repos/jruby/jruby/issues/3632","repository_url":"https://api.github.com/repos/jruby/jruby","labels_url":"https://api.github.com/repos/jruby/jruby/issues/3632/labels{/name}","comments_url":"https://api.github.com/repos/jruby/jruby/issues/3632/comments","events_url":"https://api.github.com/repos/jruby/jruby/issues/3632/events","html_url":"https://github.com/jruby/jruby/issues/3632","id":130627351,"number":3632,"title":"JRuby 1.7.24 - REXML bad encoding issue","user":{"login":"kimptoc","id":38746,"avatar_url":"https://avatars.githubusercontent.com/u/38746?v=3","gravatar_id":"","url":"https://api.github.com/users/kimptoc","html_url":"https://github.com/kimptoc","followers_url":"https://api.github.com/users/kimptoc/followers","following_url":"https://api.github.com/users/kimptoc/following{/other_user}","gists_url":"https://api.github.com/users/kimptoc/gists{/gist_id}","starred_url":"https://api.github.com/users/kimptoc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kimptoc/subscriptions","organizations_url":"https://api.github.com/users/kimptoc/orgs","repos_url":"https://api.github.com/users/kimptoc/repos","events_url":"https://api.github.com/users/kimptoc/events{/privacy}","received_events_url":"https://api.github.com/users/kimptoc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-02-02T09:36:47Z","updated_at":"2016-03-04T04:51:33Z","closed_at":"2016-03-04T04:51:33Z","body":"When we switched from 1.7.23 to 1.7.24, we started getting intermittent (1 out of 10) failures on this line.\r\n``` \r\nxml = REXML::Document.new(req.body)\r\n```\r\n\r\n``` \r\n10:50:58:115|2047-00060:TH21 ERROR: #<ArgumentError: Bad encoding name utf-8>\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/encoding.rb:11:in `encoding='\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/source.rb:55:in `encoding='\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/parsers/baseparser.rb:215:in `pull_event'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/parsers/baseparser.rb:183:in `pull'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/parsers/treeparser.rb:22:in `parse'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/document.rb:249:in `build'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/rexml/document.rb:43:in `initialize'\r\nC:/rbidev/IonPlatformPostMerge/config/RaboWriter/integration_tests/tests/mock_shareco/mock_shareco_webservice.rb:94:in `handle_bond'\r\nC:/rbidev/IonPlatformPostMerge/config/RaboWriter/integration_tests/tests/mock_shareco/mock_shareco_webservice.rb:20:in `service'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/webrick/httpserver.rb:138:in `service'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/webrick/httpserver.rb:94:in `run'\r\n/C:/Users/kimptonc/.m2/repository/org/jruby/jruby-complete/1.7.24/jruby-complete-1.7.24.jar!/META-INF/jruby.home/lib/ruby/1.9/webrick/server.rb:191:in `start_thread'\r\n...\r\nBad encoding name utf-8\r\nLine: 1\r\nPosition: 40\r\nLast 80 unconsumed characters:\r\n``` \r\nThis is the XML sent – largely the same as the other 9 times when it does work ok.\r\n ```\r\n10:50:58:115|0313-00060:TH21 INFO: <?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<bond><exchange>186</exchange><isin>XSA3</isin><sequenceNumber>1453978215004</sequenceNumber><ohlc><high>102.03</high><close>102.03</close><recentPrice>102.03</recentPrice><recentPriceDatetime>2016-01-28T12:12:03Z</recentPriceDatetime></ohlc></bond>\r\n ```\r\n\r\nRunning on Windows with JDK 1.7.0_80-b15.  Seems to be ok on Linux - at least we did not see any issues and that is what we run the main app on.\r\n\r\nWill see if I can try some tests, eg via git bisect and/or JRuby 9 to see where it starts happening"},"comment":{"url":"https://api.github.com/repos/jruby/jruby/issues/comments/192104676","html_url":"https://github.com/jruby/jruby/issues/3632#issuecomment-192104676","issue_url":"https://api.github.com/repos/jruby/jruby/issues/3632","id":192104676,"user":{"login":"headius","id":10135,"avatar_url":"https://avatars.githubusercontent.com/u/10135?v=3","gravatar_id":"","url":"https://api.github.com/users/headius","html_url":"https://github.com/headius","followers_url":"https://api.github.com/users/headius/followers","following_url":"https://api.github.com/users/headius/following{/other_user}","gists_url":"https://api.github.com/users/headius/gists{/gist_id}","starred_url":"https://api.github.com/users/headius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/headius/subscriptions","organizations_url":"https://api.github.com/users/headius/orgs","repos_url":"https://api.github.com/users/headius/repos","events_url":"https://api.github.com/users/headius/events{/privacy}","received_events_url":"https://api.github.com/users/headius/received_events","type":"User","site_admin":false},"created_at":"2016-03-04T04:51:33Z","updated_at":"2016-03-04T04:51:33Z","body":"I believe this is the same bug as #3670. After poking around the failing code, the only thing remaining that could be failing was the regular expression match `/\\AUTF-8\\z/i == 'utf-8'` happening inside `rexml/encoding.rb` logic for `encoding=`.\r\n\r\nI came up with a reproduction script:\r\n```ruby\r\n10.times.map {\r\n  Thread.new {\r\n    loop {\r\n      fail unless /\\AUTF-8\\z/i === \"utf-8\"\r\n    }\r\n  }\r\n}.map(&:join)\r\n```\r\n\r\nObviously the expression should match every time, but this fails very quickly on JRuby 1.7.24 and passes on JRuby 9.1.\r\n\r\nThe fix was by @lopex in f23bffa9acf741fe3faaec89ce286af0465c6af5.\r\n\r\n@lopex Do we have any tests for this problem? I may have found a pretty simple one if not."}}