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

liveh2o opened this Issue Feb 15, 2016 · 1 comment


None yet
3 participants

liveh2o commented Feb 15, 2016

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

jruby- :003 > ' '.try(:squeeze!)
Java::JavaLang::ArrayIndexOutOfBoundsException: 0
    from org.jruby.RubyString.squeeze_bang19(
    from org.jruby.RubyString$INVOKER$i$$INVOKER$i$squeeze_bang19.gen)
    from org.jruby.internal.runtime.methods.JavaMethod$
    from org.jruby.RubyKernel.public_send(
    from org.jruby.RubyKernel$INVOKER$s$0$0$$INVOKER$s$0$0$public_send.gen)
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(
    from org.jruby.runtime.callsite.CachingCallSite.callBlock(
    from org.jruby.internal.runtime.methods.MixedModeIRMethod.INTERPRET_METHOD(
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(
    from org.jruby.runtime.callsite.CachingCallSite.callBlock(
... 122 levels...
    from org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(
    from Users.ah.$_dot_rvm.rubies.jruby_minus_9_dot_0_dot_5_dot_0.bin.irb.invokeOther3:start(/Users/ah/.rvm/rubies/jruby-
    from Users.ah.$_dot_rvm.rubies.jruby_minus_9_dot_0_dot_5_dot_0.bin.irb.RUBY$script(/Users/ah/.rvm/rubies/jruby-
    from java.lang.invoke.MethodHandle.invokeWithArguments(
    from org.jruby.Ruby.runScript(
    from org.jruby.Ruby.runScript(
    from org.jruby.Ruby.runNormally(
    from org.jruby.Ruby.runFromMain(
    from org.jruby.Main.doRunFromMain(
    from org.jruby.Main.internalRun(
    from org.jruby.Main.main(

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 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

Merge branch 'jruby-1_7'
* jruby-1_7:
  test that public_send correctly dispatches native Java methods (closing #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 in 59db950 Feb 17, 2016


This comment has been minimized.

Show comment
Hide comment

liveh2o commented Feb 17, 2016


kares added a commit that referenced this issue Feb 18, 2016

Merge branch 'master' into ruby-2.3
* 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