Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.6.6, JRuby 1.6.7
    • Fix Version/s: JRuby 1.7.0.pre1
    • Component/s: Core Classes/Modules
    • Labels:
    • Environment:
      Mac OSX 10.7.3
    • Number of attachments :
      1

      Description

      The following code works and returns the root node on any version of JRuby prior to 1.6.6:

      require 'stringio'
      require 'rexml/document'
      str = "<?xml version=\"1.0\"?>\n<xdoc>\n\t<errorcode>0</errorcode>\n</xdoc>"
      data = StringIO.new(str)

      char = data.getc
      data.ungetc(char)

      REXML::Document.new(data).root

      As of JRuby 1.6.6 the last line above returns nil.

      Below is the output from JRuby 1.6.5:

      jruby -v -S irb
      jruby 1.6.5.1 (ruby-1.8.7-p330) (2011-12-27 1bf37c2) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
      >> require 'stringio'
      => true
      >> require 'rexml/document'
      => true
      >> str = "<?xml version=\"1.0\"?>\n<xdoc>\n\t<errorcode>0</errorcode>\n</xdoc>"
      => "<?xml version="1.0"?>\n<xdoc>\n\t<errorcode>0</errorcode>\n</xdoc>"
      >> data = StringIO.new(str)
      => #<StringIO:0x28c13406>
      >>
      ?> char = data.getc
      => 60
      >> data.ungetc(char)
      => nil
      >>
      ?> REXML::Document.new(data).root
      => xdoc ....

      On JRuby 1.6.6 (similarly for JRuby 1.6.7) :

      jruby -v -S irb
      jruby 1.6.6 (ruby-1.8.7-p357) (2012-01-30 5673572) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
      >> require 'stringio'
      => true
      >> require 'rexml/document'
      => true
      >> str = "<?xml version=\"1.0\"?>\n<xdoc>\n\t<errorcode>0</errorcode>\n</xdoc>"
      => "<?xml version="1.0"?>\n<xdoc>\n\t<errorcode>0</errorcode>\n</xdoc>"
      >> data = StringIO.new(str)
      => #<StringIO:0x539ff66f>
      >>
      ?> char = data.getc
      => 60
      >> data.ungetc(char)
      => nil
      >>
      ?> REXML::Document.new(data).root
      => nil

      Java version output:

      java -version
      java version "1.6.0_29"
      Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-11D50)
      Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

      The above code is a subset of the code in Rails 3.0.10 to reproduce the issue in a standalone environment. It is occurring under ActiveSupport::XmlMini.parse which is using REXML by default

      1. rexml.diff
        25 kB
        Patrick Mahoney

        Activity

        Hide
        Markus Gerdes added a comment -

        I also can confirm the problem (jruby 1.6.6/1.6.7).
        I'm uncertain if this is a problem with StringIO#ungetc - see example below. The problem also occurs without using it.

        1.6.6/1.6.7:

        1. jruby -v -S irb
          jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [linux-amd64-java]
          jruby-1.6.7 :001 > require 'stringio'
          => true
          jruby-1.6.7 :002 > require "rexml/document"
          => true
          jruby-1.6.7 :003 >
          jruby-1.6.7 :004 > data = StringIO.new("<?xml version=\"1.0\"?><foo>bar</foo>")
          => #<StringIO:0xb083717>
          jruby-1.6.7 :005 > doc = REXML::Document.new(data)
          => <UNDEFINED> ... </>
          jruby-1.6.7 :006 > doc.root
          => nil

        1.6.5:

        1. jruby -v -S irb
          jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [linux-amd64-java]
          jruby-1.6.5 :001 > require 'stringio'
          => true
          jruby-1.6.5 :002 > require "rexml/document"
          => true
          jruby-1.6.5 :003 >
          jruby-1.6.5 :004 > data = StringIO.new("<?xml version=\"1.0\"?><foo>bar</foo>")
          => #<StringIO:0x168497f6>
          jruby-1.6.5 :005 > doc = REXML::Document.new(data)
          => <UNDEFINED> ... </>
          jruby-1.6.5 :006 > doc.root
          => <foo> ... </>
        Show
        Markus Gerdes added a comment - I also can confirm the problem (jruby 1.6.6/1.6.7). I'm uncertain if this is a problem with StringIO#ungetc - see example below. The problem also occurs without using it. 1.6.6/1.6.7: jruby -v -S irb jruby 1.6.7 (ruby-1.8.7-p357) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [linux-amd64-java] jruby-1.6.7 :001 > require 'stringio' => true jruby-1.6.7 :002 > require "rexml/document" => true jruby-1.6.7 :003 > jruby-1.6.7 :004 > data = StringIO.new("<?xml version=\"1.0\"?><foo>bar</foo>") => #<StringIO:0xb083717> jruby-1.6.7 :005 > doc = REXML::Document.new(data) => <UNDEFINED> ... </> jruby-1.6.7 :006 > doc.root => nil 1.6.5: jruby -v -S irb jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_31) [linux-amd64-java] jruby-1.6.5 :001 > require 'stringio' => true jruby-1.6.5 :002 > require "rexml/document" => true jruby-1.6.5 :003 > jruby-1.6.5 :004 > data = StringIO.new("<?xml version=\"1.0\"?><foo>bar</foo>") => #<StringIO:0x168497f6> jruby-1.6.5 :005 > doc = REXML::Document.new(data) => <UNDEFINED> ... </> jruby-1.6.5 :006 > doc.root => <foo> ... </>
        Hide
        Patrick Mahoney added a comment - - edited

        I can reproduce this problem with JRuby 1.6.6. Replacing the rexml code with the rexml from ruby-1.8.7-p357 seems to fix the problem.

        $ cat test.rb
        require 'stringio'
        require "rexml/document"
        
        data = StringIO.new("<?xml version=\"1.0\"?><foo>bar</foo>")
        doc = REXML::Document.new(data)
        puts doc.root
        
        $ jruby test.rb
        nil
        
        # swap out JRuby's 1.8/rexml with the one in ruby-1.8.7-p357
        $ mv ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml/ ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml-orig
        $ ln -s ~/.rbenv/versions/1.8.7-p357/lib/ruby/1.8/rexml/ ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml
        
        $ jruby test.rb
        <foo>bar</foo>
        

        Edit: by the way, if I run ruby-1.8.7 using the rexml from JRuby, I can also reproduce the "nil" result.

        Show
        Patrick Mahoney added a comment - - edited I can reproduce this problem with JRuby 1.6.6. Replacing the rexml code with the rexml from ruby-1.8.7-p357 seems to fix the problem. $ cat test.rb require 'stringio' require "rexml/document" data = StringIO. new ( "<?xml version=\" 1.0\ "?><foo>bar</foo>" ) doc = REXML::Document. new (data) puts doc.root $ jruby test.rb nil # swap out JRuby's 1.8/rexml with the one in ruby-1.8.7-p357 $ mv ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml/ ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml-orig $ ln -s ~/.rbenv/versions/1.8.7-p357/lib/ruby/1.8/rexml/ ~/.rbenv/versions/jruby-1.6.6/lib/ruby/1.8/rexml $ jruby test.rb <foo>bar</foo> Edit: by the way, if I run ruby-1.8.7 using the rexml from JRuby, I can also reproduce the "nil" result.
        Hide
        Patrick Mahoney added a comment -

        Here is a diff of JRuby's rexml vs Ruby 1.8's rexml. The JRuby code was taken from the jruby-1_6 branch at commit 985cae on 25-apr-2012.

        Show
        Patrick Mahoney added a comment - Here is a diff of JRuby's rexml vs Ruby 1.8's rexml. The JRuby code was taken from the jruby-1_6 branch at commit 985cae on 25-apr-2012.
        Patrick Mahoney made changes -
        Field Original Value New Value
        Attachment rexml.diff [ 59693 ]
        Hide
        Charles Oliver Nutter added a comment -

        JRuby's 1.6 branch probably hasn't been updated (stdlib) in a while, but I'll confirm we're up-to-date on master.

        Show
        Charles Oliver Nutter added a comment - JRuby's 1.6 branch probably hasn't been updated (stdlib) in a while, but I'll confirm we're up-to-date on master.
        Hide
        Charles Oliver Nutter added a comment -

        Ok, I remember these changes now.

        These are part of fixes I made to rexml to avoid creating singleton objects or extending modules at runtime. I basically moved a bunch of encoding logic into utility classes used externally rather than leaving them as modules that get extended.

        I filed a bug with MRI here: http://bugs.ruby-lang.org/issues/5698

        Ideally I'd like to figure out what's wrong with my changes, since they improve the performance of small REXML parses quite a bit.

        Show
        Charles Oliver Nutter added a comment - Ok, I remember these changes now. These are part of fixes I made to rexml to avoid creating singleton objects or extending modules at runtime. I basically moved a bunch of encoding logic into utility classes used externally rather than leaving them as modules that get extended. I filed a bug with MRI here: http://bugs.ruby-lang.org/issues/5698 Ideally I'd like to figure out what's wrong with my changes, since they improve the performance of small REXML parses quite a bit.
        Hide
        Charles Oliver Nutter added a comment -

        I can't see what might be wrong with my changes, unfortunately, so I may just revert back to the old logic. It will slow REXML down, but this is only a 1.8 mode patch. Everyone's moving to 1.9 anyway, right?

        Show
        Charles Oliver Nutter added a comment - I can't see what might be wrong with my changes, unfortunately, so I may just revert back to the old logic. It will slow REXML down, but this is only a 1.8 mode patch. Everyone's moving to 1.9 anyway, right?
        Hide
        Charles Oliver Nutter added a comment -
        commit 70df39b69b92a1acfeff4907a386ce577801a3dc
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Tue May 15 20:04:53 2012 -0500
        
            Fix JRUBY-6517
            
            This seems to be a flaw in the patch I provided for
            http://bugs.ruby-lang.org/issues/5698. Since that patch was only
            to improve perf of REXML in Ruby 1.8 mode, I think it's better to
            have slower and working than faster and broken. Reverting.
        
        Show
        Charles Oliver Nutter added a comment - commit 70df39b69b92a1acfeff4907a386ce577801a3dc Author: Charles Oliver Nutter <headius@headius.com> Date: Tue May 15 20:04:53 2012 -0500 Fix JRUBY-6517 This seems to be a flaw in the patch I provided for http://bugs.ruby-lang.org/issues/5698. Since that patch was only to improve perf of REXML in Ruby 1.8 mode, I think it's better to have slower and working than faster and broken. Reverting.
        Charles Oliver Nutter made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Assignee Charles Oliver Nutter [ headius ]
        Fix Version/s JRuby 1.7 [ 17049 ]
        Fix Version/s JRuby 1.6.8 [ 18345 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Reid Morrison
          • Votes:
            3 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: