Thodoris Sotiropoulos created GROOVY-11475:
----------------------------------------------

             Summary: loops and flow typing can still lead to ClassCastException
                 Key: GROOVY-11475
                 URL: https://issues.apache.org/jira/browse/GROOVY-11475
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


Related to GROOVY-11474

The following program can still lead to CCE at runtime


{code:java}
class A{}

class Main {
  public static void main(String[] args) {
    def x = new A();
    while (true) {
      final A y = x;
      x = 1
    }
  }
}
 {code}
h3. Actual behavior

CCE at runtime
{code:java}
Exception in thread "main" 
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
object '1' with class 'java.lang.Integer' to class 'A'
    at 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:416)
    at 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:329)
    at 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:248)
    at 
org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
    at Main.main(Main.groovy:7) {code}
h3. Expected behavior

The code should have been rejected.
h3. Notes

Tested against commit: 29f5a1eb0c174514a56e94892d07f417adbad45f



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to