Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
Description
I have the following program
class A { Object clone() { return null; } } class Main { public static void main(Object y) { def x x = new A() if (false ){ x = new A() } else { if (true) { x = 1 } } x.clone(); } }
Actual behavior
The program compiles, but I receive the following error at runtime:
Exception in thread "main" java.lang.ClassCastException: class java.lang.Integer cannot be cast to class A (java.lang.Integer is in module java.base of loader 'bootstrap'; A is in unnamed module of loader 'app') at Main.main(test.groovy:16)
Expected behavior
The code should have been rejected with
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
test.groovy: 12: Cannot access method: clone() of class: java.lang.Object @ line 12, column 5.
x.clone();
^1 error
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-9786 SC: cast exception for variable assigned within conditional blocks
- Closed