[
https://issues.apache.org/jira/browse/GROOVY-11490?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-11490.
----------------------------------
Fix Version/s: 5.0.0-alpha-11
Resolution: Fixed
https://github.com/apache/groovy/commit/a8188364fa108d22a9cf1ef35c4ce2e946b3f7a6
> 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
> Assignee: Eric Milles
> Priority: Minor
> Fix For: 5.0.0-alpha-11
>
>
> 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)