Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-2972

groovy.lang.ObjectRange.size() disobeys its contract for large ranges of Long values.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.5.6, 1.6-beta-1
    • 2.5.0-alpha-1
    • groovy-jdk
    • None

    Description

      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()

      Attachments

        Activity

          People

            paulk Paul King
            sirjective Christian Semrau
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: