Issue Details (XML | Word | Printable)

Key: GROOVY-2187
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: BarzilaiSpinak
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 09/Oct/07 04:57 PM   Updated: 22/Nov/07 05:20 AM   Resolved: 09/Oct/07 06:56 PM
Return to search
Component/s: None
Affects Version/s: 1.0, 1.1-beta-1, 1.1-beta-2, 1.1-beta-3
Fix Version/s: 1.1-rc-1

Time Tracking:
Not Specified


 Description  « Hide

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



Paul King made changes - 09/Oct/07 06:55 PM
Field Original Value New Value
Assignee Paul King [ paulk ]
Paul King added a comment - 09/Oct/07 06:56 PM

Fixed in head with the following test:
String s = 'hello 10'
def gs = "hello {5+5}"
def expected = ["h", "e", "l", "l", "o", " ", "1", "0"]
assert s.toList() == expected
assert s as String[] == expected
assert gs as String[] == expected


Paul King made changes - 09/Oct/07 06:56 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 1.1-rc-1 [ 13165 ]
Paul King made changes - 22/Nov/07 05:20 AM
Status Resolved [ 5 ] Closed [ 6 ]