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

Hash#shift fails at capacity boundaries #5392

Closed
headius opened this Issue Oct 31, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@headius
Copy link
Member

headius commented Oct 31, 2018

The Hash#shift method appears to break at capacity boundaries, such as the default size of 8:

h = {}
8.times {|j| h[j] = j}
p h
h.shift

This produces an ArrayIndexOutOfBoundsException:

Unhandled Java exception: java.lang.ArrayIndexOutOfBoundsException: 16
java.lang.ArrayIndexOutOfBoundsException: 16
                shift at org/jruby/RubyHash.java:1921
                 call at org/jruby/RubyHash$INVOKER$i$0$0$shift.gen:-1
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:323
                 call at org/jruby/runtime/callsite/CachingCallSite.java:139
   invokeOther5:shift at -e:1
               <main> at -e:1
  invokeWithArguments at java/lang/invoke/MethodHandle.java:627
                 load at org/jruby/ir/Compiler.java:94
            runScript at org/jruby/Ruby.java:852
          runNormally at org/jruby/Ruby.java:771
          runNormally at org/jruby/Ruby.java:789
          runFromMain at org/jruby/Ruby.java:601
        doRunFromMain at org/jruby/Main.java:415
          internalRun at org/jruby/Main.java:307
                  run at org/jruby/Main.java:234
                 main at org/jruby/Main.java:206

The cause appears to be lack of a guard for the end value being just beyond the end of the current entries store.

Fix coming.

@headius headius added this to the JRuby 9.2.1.0 milestone Oct 31, 2018

headius added a commit to headius/jruby that referenced this issue Oct 31, 2018

headius added a commit to headius/jruby that referenced this issue Oct 31, 2018

Add spec for Hash#shift at capacity. See jruby#5392.
This spec attempts to construct a number of different size hashes
and shift one value from each, since we can't know what default
sizes a given implenentation uses as its capacity levels. The
resulting successful sizes are aggregated and used for a single
expectation.

eregon added a commit to ruby/spec that referenced this issue Nov 27, 2018

Add spec for Hash#shift at capacity. See jruby/jruby#5392.
This spec attempts to construct a number of different size hashes
and shift one value from each, since we can't know what default
sizes a given implenentation uses as its capacity levels. The
resulting successful sizes are aggregated and used for a single
expectation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.