-
-
Notifications
You must be signed in to change notification settings - Fork 942
Closed
Description
Environment
$ jruby --version
jruby 9.2.1.0 (2.5.0) 2018-11-06 7b14404 OpenJDK 64-Bit Server VM 25.191-b12 on 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12 +jit [linux-x86_64]
$ echo $JRUBY_OPTS
$ uname -a
Linux the_hostname 4.15.0-45-generic #48~16.04.1-Ubuntu SMP Tue Jan 29 18:03:48 UTC 2019 x86_64 x86_64 x86_64 GNU/LinuxExpected Behavior
I expect that slicing Java arrays with negative indexes works like it does in Ruby arrays, or even like it used to work for Java arrays before 9.2.1.0.
See https://ruby-doc.org/core-2.5.0/Array.html#method-i-slice, with emphasis on:
Negative indices count backward from the end of the array (-1 is the last element).
Here is an example of the behavior I would expect:
# Ruby array slicing with a negative index in 9.2.1.0 works fine:
jruby-9.2.1.0 :001 > [1,2][0..-1]
=> [1, 2]# Java array slicing with a negative index in 9.2.0.0 (last version known to work) works fine:
jruby-9.2.0.0 :001 > a = [1,2].to_java[0..-1]
=> java.lang.Object[1, 2]@1e730495 Actual Behavior
Instead, what happens is that the last element of the Java array is lost:
# Java array slicing with a negative index in 9.2.1.0 doesn't work any more:
jruby-9.2.1.0 :001 > a = [1,2].to_java[0..-1]
=> java.lang.Object[1]@6a472554 Note that this issue was introduced in 9.2.1.0 and remains in the latest released version 9.2.7.0.
Reactions are currently unavailable