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

IntRange.step overflows near Integer.MAX_VALUE or Integer.MIN_VALUE

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.5.6, 1.6-beta-1
    • Fix Version/s: 2.2.0-beta-2
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      (Integer.MAX_VALUE..Integer.MAX_VALUE).step(1){println it; assert it > 0}
      
      (Integer.MIN_VALUE..Integer.MIN_VALUE).step(-1){println it; assert it < 0}
      
      (0..2000000000).step(1000000000){println it; assert it >= 0}
      

      As expected for the first line, the closure is called once with Integer.MAX_VALUE, but after that it is called with Integer.MIN_VALUE.
      The second line shows the opposite overflow at Integer.MIN_VALUE.
      The third line shows the overflow in yet another case.

      ObjectRange seems not to suffer from this overflow.

        Attachments

          Activity

            People

            • Assignee:
              pschumacher Pascal Schumacher
              Reporter:
              sirjective Christian Semrau
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: