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

String containing an integer is considered a character for ranges

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 1.0-JSR-4
    • 1.0-JSR-5
    • None
    • None

    Description

      Let's say I have a method that receives a string that contains an integer (0..9). If I use that parameter as part of a range, Groovy considers it a character which causes some really unexpected effects. For example:

      str = "5"
      // ...
      lastNumber = str;
      myRange = 0..lastNumber
      myRange.each {
      print it
      }

      I would expect it to print: 012345
      Instead it takes the character value of 5 and prints: 0123456789101112 ... 515253

      Is this what is really wanted or should this be considered a bug? At least it makes it pretty easy to make mistakes.

      Attachments

        Activity

          People

            blackdrag Jochen Theodorou
            mhalttu Markus Halttunen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: