Skip to content

Object#try(:squeeze!) raises an array index out of bounds exception #3668

@liveh2o

Description

@liveh2o

Using Active Support's Object#try method with String#squeeze raises a Java ArrayIndexOutOfBoundsException:

jruby-9.0.5.0 :003 > ' '.try(:squeeze!)
Java::JavaLang::ArrayIndexOutOfBoundsException: 0
    from org.jruby.RubyString.squeeze_bang19(RubyString.java:4611)
    from org.jruby.RubyString$INVOKER$i$squeeze_bang19.call(RubyString$INVOKER$i$squeeze_bang19.gen)
    from org.jruby.internal.runtime.methods.JavaMethod$JavaMethodN.call(JavaMethod.java:729)
    from org.jruby.RubyKernel.public_send(RubyKernel.java:1823)
    from org.jruby.RubyKernel$INVOKER$s$0$0$public_send.call(RubyKernel$INVOKER$s$0$0$public_send.gen)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:273)
    from org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:79)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:83)
    from org.jruby.ir.instructions.CallBase.interpret(CallBase.java:414)
    from org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:348)
    from org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:77)
    from org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(MixedModeIRMethod.java:140)
    from org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:126)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:273)
    from org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:79)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:83)
... 122 levels...
    from org.jruby.internal.runtime.methods.MixedModeIRMethod.call(MixedModeIRMethod.java:196)
    from org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:197)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:313)
    from org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:163)
    from Users.ah.$_dot_rvm.rubies.jruby_minus_9_dot_0_dot_5_dot_0.bin.irb.invokeOther3:start(/Users/ah/.rvm/rubies/jruby-9.0.5.0/bin/irb)
    from Users.ah.$_dot_rvm.rubies.jruby_minus_9_dot_0_dot_5_dot_0.bin.irb.RUBY$script(/Users/ah/.rvm/rubies/jruby-9.0.5.0/bin/irb:13)
    from java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:627)
    from org.jruby.ir.Compiler$1.load(Compiler.java:111)
    from org.jruby.Ruby.runScript(Ruby.java:817)
    from org.jruby.Ruby.runScript(Ruby.java:809)
    from org.jruby.Ruby.runNormally(Ruby.java:747)
    from org.jruby.Ruby.runFromMain(Ruby.java:569)
    from org.jruby.Main.doRunFromMain(Main.java:415)
    from org.jruby.Main.internalRun(Main.java:310)
    from org.jruby.Main.run(Main.java:239)
    from org.jruby.Main.main(Main.java:201)

To reproduce, with Active Support installed:

require 'active_support'
require 'active_support/core_ext'

# Works:
#   ' '.squeeze
#   ' '.squeeze!
#   ''.try(:squeeze)
#   ''.try(:squeeze!)
#
# Does not work:
#   ' '.try(:squeeze)
#   ' '.try(:squeeze!)
' '.try(:squeeze)

I was able reproduce this in JRuby 9.0.x.x and JRuby 1.7.x with Active Support 4.2 back to 3.2. It seems to be limited to the squeeze method.

Let me know if you need any other info.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions