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

Regression on java array slices with a negative index introduced in 9.2.1.0 #5698

Closed
manu-crealytics opened this Issue Apr 15, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@manu-crealytics
Copy link
Contributor

manu-crealytics commented Apr 15, 2019

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

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

@headius headius added this to the JRuby 9.2.8.0 milestone Apr 16, 2019

@headius

This comment has been minimized.

Copy link
Member

headius commented Apr 16, 2019

@kares Any thoughts on why this regressed?

@kares kares self-assigned this Apr 16, 2019

@kares

This comment has been minimized.

Copy link
Member

kares commented Apr 16, 2019

seems like we (I most likely) did the range exclude end condition upside down :

kares@clevo:~/workspace/oss/jruby$ bin/jruby -e "p [1,2,3,4].to_java[0..-1]"
java.lang.Object[1, 2, 3]@5f282abb
kares@clevo:~/workspace/oss/jruby$ bin/jruby -e "p [1,2,3,4].to_java[0...-1]"
java.lang.Object[1, 2, 3, 4]@5f282abb

... fix coming for 9.2.8, thanks for bringing this up

@kares

This comment has been minimized.

Copy link
Member

kares commented Apr 16, 2019

here's the responsible commit: e9c28b0#diff-7a04ea909e92e7b40f50a03b7bf03390R736

@kares kares closed this in 64e48c2 Apr 16, 2019

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.