Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.4.3, 2.4.4, 2.4.5
-
None
-
all?
Tested with Ubuntu 14.04.3 LTS (64 Bit) | MacOS 10.11 and Groovy 2.4.5, 2.3.4
Description
Problem
subClass.with {
type = ['String']
}
Should change SubClass.type and not TopClass.type.
The script works fine with type2 instead of type. Is type a reserved word? I can't find any documentation about this.
Unit-Test / Groovy Console-Test
class SubClass{ List type } class TopClass{ int type = 10 @Lazy List something = { List tmp = [] for(int i = 0; i < 5; i++){ def subClass = new SubClass() subClass.with { type = ['String'] // throws org.codehaus.groovy.runtime.typehandling.GroovyCastException } tmp.add(subClass) } tmp }() } def topClass = new TopClass() println GroovySystem.version println(topClass.type) println(topClass.something) println(topClass.type)
Exception
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '[String]' with class 'java.util.ArrayList' to class 'int' at TopClass$_getSomething_closure1$_closure2.doCall(ConsoleScript3:15) at TopClass$_getSomething_closure1.doCall(ConsoleScript3:14) at TopClass$_getSomething_closure1.doCall(ConsoleScript3) at TopClass.getSomething(ConsoleScript3:11) at ConsoleScript3.run(ConsoleScript3:26)
Attachments
Issue Links
- breaks
-
GROOVY-9655 Groovy 3.0.5 regression with the "with" keyword
- Closed
- relates to
-
GROOVY-11056 modified behavior of variable resolution within Closure
- Closed