Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
I have the following program
class Test { public static void main(String[] args) { def x = 1 Closure m = null if (true) { m = {x = ""} } x = 1 m() } }
Actual behavior
The code compiles, but I get ClassCastException at runtime
Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object '' with class 'java.lang.String' to class 'java.lang.Integer' at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:294) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248) at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336) at Test$_main_closure1.doCall(test.groovy:6) at Test$_main_closure1.call(test.groovy) at Test.main(test.groovy:9)
Expected behavior
The code should have been rejected.
Attachments
Issue Links
- is related to
-
GROOVY-11068 VerifyError when using generic container in closure
- Closed