Thodoris Sotiropoulos created GROOVY-11490: ----------------------------------------------
Summary: ClassCastException when assigning a lambda returning null into a SAM expecting a primitive Key: GROOVY-11490 URL: https://issues.apache.org/jira/browse/GROOVY-11490 Project: Groovy Issue Type: Bug Components: Static Type Checker Reporter: Thodoris Sotiropoulos I have the following program {code:java} import java.util.function.IntSupplier; public class Test { public static void main(String[] args) { IntSupplier x = () -> null; int y = x.getAsInt(); } } {code} h3. Actual behavior The code compiles but there's CCE at runtime {code:java} Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 'null' to class 'int'. Try 'java.lang.Integer' instead at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177) at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.intUnbox(DefaultTypeTransformation.java:85) at Test$_main_lambda1.doCall(test.groovy:5) at Test.main(test.groovy:6) {code} h3. Expected behavior The code should have been rejected. -- This message was sent by Atlassian Jira (v8.20.10#820010)