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

GString as String[] returns a 1-element array with the whole text

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0, 1.1-beta-1, 1.1-beta-2, 1.1-beta-3
    • 1.1-rc-1
    • None
    • None

    Description

      This is an old bug.
      Case 1)
      groovy> String str= "hello 10"
      groovy> str as String[]
      Result: ["h", "e", "l", "l", "o", " ", "1", "0"]

      That is, an array of String with one element per character in the original String.

      Case 2)
      groovy> def i= 10
      groovy> def gstr= "hello $i"
      groovy> gstr as String[]
      Result: ["hello 10"]

      That is, an array of String, with only one element consisting of the whole rendered String.

      This is inconsistent behaviour and may give undesired results when calling methods that expect an array of String

      Attachments

        Activity

          People

            paulk Paul King
            barspi Barzilai Spinak
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: