Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
liveh2o opened this issue Feb 15, 2016 · 1 comment
Closed

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

liveh2o opened this issue Feb 15, 2016 · 1 comment
Assignees
Milestone

Comments

@liveh2o
Copy link

liveh2o commented Feb 15, 2016

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.

@enebo enebo added this to the JRuby 9.1.0.0 milestone Feb 15, 2016
@kares kares self-assigned this Feb 17, 2016
kares added a commit to kares/jruby that referenced this issue Feb 17, 2016
* jruby-1_7:
  test that public_send correctly dispatches native Java methods (closing jruby#3668)
  generic JavaMethodN call with [] args should delegate to correct arity (due overriders)
  explicitly mark required arg count for RubyString squeeze impls
@kares kares closed this as completed in 59db950 Feb 17, 2016
@liveh2o
Copy link
Author

liveh2o commented Feb 17, 2016

5488e624-2f5d-11e4-9e43-74ca646af77b

kares added a commit that referenced this issue Feb 18, 2016
* master: (28 commits)
  single Unsafe retrieval is enough - do not do it over again in StringSupport
  [test] add and pend load module wrapping test - does not work for this case currently
  make JavaMethod arity sub-classes open-closed with call overrides (for less surprises)
  Add a simple issue template for contributors.
  [Truffle] Strip out internal NilNodes when flattening a sequence.
  [Truffle] Break down IfNode into If, IfElse and Unless so they can be simpler.
  [Truffle] BreakShellException is dead code.
  [Truffle] Tidy up NotNode.
  [Truffle] Tidy up IfNode.
  [Truffle] Tidy up OrNode.
  [Truffle] Tidy up AndNode.
  [Truffle] Couple of minor cosmetic fixes to the backtrace package.
  [Truffle] Interleaving Java should be configured per-formatter.
  [Truffle] Remove print_interleaved_backtrace, as we can do it with -Xtruffle.backtraces.interleave_java now.
  [Truffle] Option to interleave Java stacktraces in Ruby backtraces.
  [Truffle] Store Java exceptions in some cases.
  [Truffle] Optionally store Java stack traces in Ruby backtraces.
  [Truffle] Simplify long-winded comment.
  [Truffle] Move check_ambiguous_arguments to allowed failures.
  test that public_send correctly dispatches native Java methods (closing #3668)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants