Just stumbled about an entry in the Groovy mailing list
def input = '''<tag id="12" />''' def tag = new XmlParser().parseText(input) tag.attribute("id").value = "ABCD" println tag.attribute("id") ==> AB
Oops. The object returned by tag.attribute(“id”) is of type String (i.e. java.lang.String) and not of some type XmlAttribute. And the ‘value’ is the private final (sic!) variable containing the String’s content (a char array). And Groovy allows us to change that value … making String mutable.
... println tag.attribute("id").value ==> [A, B, C, D]
I always had the feeling, that Groovy was programmed first and then designed afterwards. In the last years they progressed nicely, but this makes me doubt again. This issue has been known since May 2007. But I think they just realized what it means: “Yikes! String is mutable!”
Please vote for the issue to be fixed.