groovy

Println behavior for collections, strings and gstrings [minor breaking change]

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.6-rc-2
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

The println behavior for strings in collections is confusing. There should be no exclamation mark in line 8 of the following script. It is particularly confusing, as the behavior is different for strings and gstrings.

import org.codehaus.groovy.runtime.InvokerHelper

def g = 'g'
def string = 'groovy'
def gString = "${g}roovy"
println string // groovy
println gString // groovy
println([string]) // ["groovy"]  !!!!! This should be [groovy]
println([string].toString()) // [groovy]
System.out.println([string]) // [groovy]
println([gString]) // [groovy]

// The culprit
assert '"groovy"' == InvokerHelper.format(string, true)

Issue Links

Activity

Hide
Paul King added a comment -

Edited title for better perusing of release notes

Show
Paul King added a comment - Edited title for better perusing of release notes
Hide
Russel Winder added a comment -

As noted in the email, this has caused a few people a bit of aggravation.

I think creating the consistency is critical, and I can live with the solution if that is the general view of what should be done. I would have considered adding quotes around all strings instead of the removal that has happened. An example issue, it is not clear what the types are in:

[ fred , 1 , bert , 2 ]

whereas it is less so in:

[ "fred" , "1" , "bert" , 2 ]

I haven't reopened the issue as it may not need it but perhaps we should.

Show
Russel Winder added a comment - As noted in the email, this has caused a few people a bit of aggravation. I think creating the consistency is critical, and I can live with the solution if that is the general view of what should be done. I would have considered adding quotes around all strings instead of the removal that has happened. An example issue, it is not clear what the types are in:
[ fred , 1 , bert , 2 ]
whereas it is less so in:
[ "fred" , "1" , "bert" , 2 ]
I haven't reopened the issue as it may not need it but perhaps we should.
Hide
blackdrag blackdrag added a comment -

fix version is wrong

Show
blackdrag blackdrag added a comment - fix version is wrong
Hide
blackdrag blackdrag added a comment -

fix version is corrected

Show
blackdrag blackdrag added a comment - fix version is corrected

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: