Skip to content

Hash#shift fails at capacity boundaries #5392

@headius

Description

@headius

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions