You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Thibault Kruse (JIRA)" <ji...@apache.org> on 2015/10/14 16:35:05 UTC

[jira] [Commented] (GROOVY-2972) groovy.lang.ObjectRange.size() disobeys its contract for large ranges of Long values.

    [ https://issues.apache.org/jira/browse/GROOVY-2972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14957021#comment-14957021 ] 

Thibault Kruse commented on GROOVY-2972:
----------------------------------------

I am not sure about fixing IntRange. I believe it would be possible to extend it to allow greater ranges and return Integer.MAX_VALUE when the size is larger, but I am scared that some code might rely on size() returning the actual value, since that was the behavior up to now.

I could not reproduce the example:
println (new IntRange(-1, Integer.MAX_VALUE).size()) // -2147483647
but Christian might have been talking about ObjectRange instead...

> groovy.lang.ObjectRange.size() disobeys its contract for large ranges of Long values.
> -------------------------------------------------------------------------------------
>
>                 Key: GROOVY-2972
>                 URL: https://issues.apache.org/jira/browse/GROOVY-2972
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 1.5.6, 1.6-beta-1
>            Reporter: Christian Semrau
>            Priority: Minor
>
> groovy.lang.ObjectRange.size() disobeys its contract for large ranges of Long values: "Returns the number of elements in this list. If this list contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE."
> println (new ObjectRange(0L, (long)Integer.MAX_VALUE).size())  // -2147483648
> println (new ObjectRange(0L, (2L<<32)-2).size())  // -1
> A similar error is to be expected for BigDecimal ranges and other ranges larger than Integer.MAX_VALUE, though with other kinds of ranges the computation of size takes a while.
> Expected behaviour:
> assert Integer.MAX_VALUE == new ObjectRange(0L, Integer.MAX_VALUE + 1L).size()



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)