[ 
https://issues.apache.org/jira/browse/GROOVY-11440?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles resolved GROOVY-11440.
----------------------------------
    Fix Version/s: 5.0.0-alpha-11
       Resolution: Fixed

https://github.com/apache/groovy/commit/ab5a811f5bffecf439714bbc9b073c3f66acf42c

> invalid reference to an array constructor leads to type unsafe results
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-11440
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11440
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Priority: Minor
>              Labels: groovy
>             Fix For: 5.0.0-alpha-11
>
>
> I have the following program
> {code:java}
> import java.util.function.*;
> class A{
> }
> class Test {
>   public static void main(String[] args) {
>     Function<Object, A[]> x = A[]::new;
>     A[] y = x.apply(new Object());
>   }
> } {code}
> h3. Actual behavior
> The code compiles, and I get a ClassCastException:
> {code:java}
> Exception in thread "main" 
> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
> object 'java.lang.Object@63d4e2ba' with class 'java.lang.Object' to class 
> 'int'
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177)
>     at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.intUnbox(DefaultTypeTransformation.java:85)
>     at Test.ctorRef$main$0(test.groovy)
>     at Test.main(test.groovy:13) {code}
> h3. Actual behavior
> The code should have been rejected.



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

Reply via email to