Pepijn Van Eeckhoudt created JRUBY-6548: -------------------------------------------
Summary: REXML error when reading files containing ISO-8859-1 encoded data Key: JRUBY-6548 URL: https://jira.codehaus.org/browse/JRUBY-6548 Project: JRuby Issue Type: Bug Components: Standard Library Affects Versions: JRuby 1.6.7 Environment: Arch Linux OpenJDK 1.7 JRuby 1.6.7 Reporter: Pepijn Van Eeckhoudt Assignee: Thomas E Enebo Attachments: ICONV.rb, test.rb, test.xml The attached script decodes the attached xml file. The xml file is encoded in ISO-8859-1. This triggers the iconv based decoding in rexml/encoding.rb:36 ICONV.rb is implemented as listed below. As far as I can tell this can never work. @encoding is not defined in ICONVEncoder so it will always be nil. In the end this causes the TypeError listed below. The version of ICONV.rb that is included in JRuby does not match the one from http://www.germane-software.com/software/rexml/. The only reference to the diff between the two I could find is https://gist.github.com/1420725. The change that is applied there is what introduced this error. Before that patch the iconv decoding methods where defined in the REXML::Encoding module which does have the @encoding field. I've attached a possible fix in the form of a patched version of ICONV.rb. ICONV.rb {code} class ICONVEncoder def decode(str) Iconv.conv(UTF_8, @encoding, str) end def encode(content) Iconv.conv(@encoding, UTF_8, content) end end iconv = ICONVEncoder.new register("ICONV") do |obj| Iconv.conv(UTF_8, obj.encoding, nil) obj.encoder = iconv end {code} TypeError that is triggered during decoding {code} TypeError: can't convert NilClass into String initialize at org/jruby/RubyIconv.java:207 conv at org/jruby/RubyIconv.java:391 encode at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/encodings/ICONV.rb:12 encoding= at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/source.rb:55 initialize at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/source.rb:45 initialize at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/source.rb:160 create_from at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/source.rb:16 stream= at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/parsers/baseparser.rb:121 initialize at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/parsers/baseparser.rb:110 initialize at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/parsers/treeparser.rb:9 build at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/document.rb:227 initialize at /opt/jruby-1.6.7/lib/ruby/1.8/rexml/document.rb:43 {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email