You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Sean Fitts (JIRA)" <ji...@apache.org> on 2019/01/22 17:59:00 UTC
[jira] [Updated] (GROOVY-8966) Exclusive NumberRange is converted
to inclusive when used by List.getAt(range).
[ https://issues.apache.org/jira/browse/GROOVY-8966?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sean Fitts updated GROOVY-8966:
-------------------------------
Description:
When constructing an exclusive range, if the types of the left and right sides are explicitly typed and don't match then the result at runtime is an instance of `NumberRange`. When this is passed to the List.getAt helper method it calls `DefaultGroovyMethodsSupport.subListBorders` which at line 88 returns an instance of `RangeInfo` for an inclusive range.
Contrast this with the code in IntRange which explicitly checks the `inclusive` flag and returns the correct range info.
The following code blocks runs:
{code:java}
def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
long x = 10
println array[x..<11L]
{code}
The following code produces an IndexOutOfBounds exception:
{code:java}
def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
int x = 10
println array[x..<11L]
// Another broken variant
def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Long x = 10
println array[x..<11L] // both longs, but still get NumberRange due to boxed vs unboxed{code}
was:
When constructing an exclusive range, if the types of the left and right sides are explicitly typed and don't match then the result at runtime is an instance of `NumberRange`. When this is passed to the List.getAt helper method it calls `DefaultGroovyMethodsSupport.subListBorders` which at line 88 returns an instance of `RangeInfo` for an inclusive range.
Contrast this with the code in IntRange which explicitly checks the `inclusive` flag and returns the correct range info.
The following code blocks runs:
{code:java}
def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
long x = 10
println array[x..<11L]
{code}
The following code produces an IndexOutOfBounds exception:
{code:java}
def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
int x = 10
println array[x..<11L]
{code}
> Exclusive NumberRange is converted to inclusive when used by List.getAt(range).
> -------------------------------------------------------------------------------
>
> Key: GROOVY-8966
> URL: https://issues.apache.org/jira/browse/GROOVY-8966
> Project: Groovy
> Issue Type: Bug
> Components: groovy-runtime
> Affects Versions: 2.5.4
> Reporter: Sean Fitts
> Priority: Minor
>
> When constructing an exclusive range, if the types of the left and right sides are explicitly typed and don't match then the result at runtime is an instance of `NumberRange`. When this is passed to the List.getAt helper method it calls `DefaultGroovyMethodsSupport.subListBorders` which at line 88 returns an instance of `RangeInfo` for an inclusive range.
> Contrast this with the code in IntRange which explicitly checks the `inclusive` flag and returns the correct range info.
> The following code blocks runs:
> {code:java}
> def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> long x = 10
> println array[x..<11L]
> {code}
> The following code produces an IndexOutOfBounds exception:
> {code:java}
> def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> int x = 10
> println array[x..<11L]
> // Another broken variant
> def array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> Long x = 10
> println array[x..<11L] // both longs, but still get NumberRange due to boxed vs unboxed{code}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)