Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.5
-
Fix Version/s: 1.8.2
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
A MethodSelectionException is thrown when appending an empty list to a GString that contains a ${} expression. Note that no exception is thrown if the GString does not contain a ${} expression or if the list is nonempty. The exception thrown is:
Caught: org.codehaus.groovy.runtime.metaclass.MethodSelectionException: Could not find which method plus() to invoke from this list: public groovy.lang.GString groovy.lang.GString#plus(groovy.lang.GString) public groovy.lang.GString groovy.lang.GString#plus(java.lang.String)
No other concatenation I've tried has this behavior. So the following line throws the exception:
"GString concat ${'a'}" + []
None of the following throw anything:
"GString concat ${'a'}" + ['abc'] // Concatenating a nonempty list "GString concat " + [] // Concatenating an empty list, but not using ${} in the GString // Concatenating various other object types ['abc', '', null, [:], 0, 1, false, new Object[0]].each { "GString concat ${'a'}" + it }
I would expect the behavior of appending an empty list to be consistent with appending any other list (or object type).
Just wanted to note that the attached testcase passes in Groovy 1.8.2 and above.