Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.7.0.pre1
    • Fix Version/s: JRuby 1.7.0.pre2
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Strange java.lang.ArrayIndexOutOfBoundsException raised in String#each_line with specifying a separator.

      $ jruby -v -e '"a".each_line("ab") { |x| p x }'
      jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
      ByteList.java:1291:in `memcmp': java.lang.ArrayIndexOutOfBoundsException: 1
      	from RubyString.java:7095:in `each_lineCommon19'
      	from RubyString.java:7020:in `each_line19'
      	from RubyString$INVOKER$i$each_line19.gen:-1:in `call'
      	from CachingCallSite.java:322:in `cacheAndCall'
      	from CachingCallSite.java:178:in `callBlock'
      	from CachingCallSite.java:187:in `callIter'
      	from -e:1:in `__file__'
      	from -e:-1:in `load'
      	from Ruby.java:778:in `runScript'
      	from Ruby.java:771:in `runScript'
      	from Ruby.java:648:in `runNormally'
      	from Ruby.java:497:in `runFromMain'
      	from Main.java:375:in `doRunFromMain'
      	from Main.java:264:in `internalRun'
      	from Main.java:230:in `run'
      	from Main.java:214:in `run'
      	from Main.java:194:in `main'
      

        Activity

        Hide
        Naohisa Goto added a comment -

        Oops, some Ruby code is recognized as text markup in the above...

        $ jruby -v -e '"a".each_line("ab") do |x| p x; end'
        jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
        ByteList.java:1291:in `memcmp': java.lang.ArrayIndexOutOfBoundsException: 1
        from RubyString.java:7095:in `each_lineCommon19'
        from RubyString.java:7020:in `each_line19'
        from RubyString$INVOKER$i$each_line19.gen:-1:in `call'
        from CachingCallSite.java:322:in `cacheAndCall'
        from CachingCallSite.java:178:in `callBlock'
        from CachingCallSite.java:187:in `callIter'
        from -e:1:in `_file_'
        from -e:-1:in `load'
        from Ruby.java:778:in `runScript'
        from Ruby.java:771:in `runScript'
        from Ruby.java:648:in `runNormally'
        from Ruby.java:497:in `runFromMain'
        from Main.java:375:in `doRunFromMain'
        from Main.java:264:in `internalRun'
        from Main.java:230:in `run'
        from Main.java:214:in `run'
        from Main.java:194:in `main'

        In MRI, it works.
        $ ruby -v -e '"a".each_line("ab") do |x| p x; end'
        ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
        "a"

        Show
        Naohisa Goto added a comment - Oops, some Ruby code is recognized as text markup in the above... $ jruby -v -e '"a".each_line("ab") do |x| p x; end' jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java] ByteList.java:1291:in `memcmp': java.lang.ArrayIndexOutOfBoundsException: 1 from RubyString.java:7095:in `each_lineCommon19' from RubyString.java:7020:in `each_line19' from RubyString$INVOKER$i$each_line19.gen:-1:in `call' from CachingCallSite.java:322:in `cacheAndCall' from CachingCallSite.java:178:in `callBlock' from CachingCallSite.java:187:in `callIter' from -e:1:in `_ file _' from -e:-1:in `load' from Ruby.java:778:in `runScript' from Ruby.java:771:in `runScript' from Ruby.java:648:in `runNormally' from Ruby.java:497:in `runFromMain' from Main.java:375:in `doRunFromMain' from Main.java:264:in `internalRun' from Main.java:230:in `run' from Main.java:214:in `run' from Main.java:194:in `main' In MRI, it works. $ ruby -v -e '"a".each_line("ab") do |x| p x; end' ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux] "a"
        Hide
        Charles Oliver Nutter added a comment -

        Icky! Looks like when the separator is larger than one byte and there's not enough bytes left in the string, we're walking off the end. I have a fix.

        Show
        Charles Oliver Nutter added a comment - Icky! Looks like when the separator is larger than one byte and there's not enough bytes left in the string, we're walking off the end. I have a fix.
        Hide
        Charles Oliver Nutter added a comment -
        commit 2a0a2215ec4303856e7f65e6c000e205112f6087
        Author: Charles Oliver Nutter <headius@headius.com>
        Date:   Mon Aug 6 12:21:13 2012 -0500
        
            Fix JRUBY-6819
            
            java.lang.ArrayIndexOutOfBoundsException in String#each_line
            
            When the string is shorter than the separator, we walk off the
            end. Modified it to check that there's enough bytes left in the
            string before memcmp'ing it.
        
        :100644 100644 97e4259... 48e0a15... M	src/org/jruby/RubyString.java
        
        Show
        Charles Oliver Nutter added a comment - commit 2a0a2215ec4303856e7f65e6c000e205112f6087 Author: Charles Oliver Nutter <headius@headius.com> Date: Mon Aug 6 12:21:13 2012 -0500 Fix JRUBY-6819 java.lang.ArrayIndexOutOfBoundsException in String#each_line When the string is shorter than the separator, we walk off the end. Modified it to check that there's enough bytes left in the string before memcmp'ing it. :100644 100644 97e4259... 48e0a15... M src/org/jruby/RubyString.java
        Hide
        Charles Oliver Nutter added a comment -

        Pull request sent to ruby-core for a test: https://github.com/ruby/ruby/pull/151

        Show
        Charles Oliver Nutter added a comment - Pull request sent to ruby-core for a test: https://github.com/ruby/ruby/pull/151

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Naohisa Goto
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: