[ 
https://issues.apache.org/jira/browse/GROOVY-11371?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17860214#comment-17860214
 ] 

Eric Milles edited comment on GROOVY-11371 at 6/26/24 6:23 PM:
---------------------------------------------------------------

Conversion from {{Double[]}} to {{double[]}} is supported.  All values besides 
null are boxed.  In fact, any type that is convertible to {{Number}} works as 
well.  Adding a type-check error is a possibility, but will not help the 
{{IllegalArgumentException}} outside STC.


was (Author: emilles):
Conversion from {{Double[]}} to {{double[]}} is supported.  All values besides 
null are boxed.  In fact, any type that is convertible to {{Number}} works as 
well.  Adding a type-check error is a possibility, but will not help the odd 
{{IllegalArgumentException}} outside STC.

> unsafe conversion of array of reference type to an array of primitive type
> --------------------------------------------------------------------------
>
>                 Key: GROOVY-11371
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11371
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Eric Milles
>            Priority: Minor
>
> I have the following program
> {code:java}
> class Test {
>   public static void main(String[] args) {
>     double[] z = new Double[]{null};
>   }
> } {code}
> h3. Actual behavior
> The compiler accepts the program. However, I get the following exception at 
> runtime.
>  
> {code:java}
> Exception in thread "main" java.lang.IllegalArgumentException
>         at java.base/java.lang.reflect.Array.set(Native Method)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.asArray(DefaultTypeTransformation.java:459)
>         at 
> org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:228)
>         at 
> org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
>         at Test.main(test.groovy:3)
>  {code}
> h3. Expected behavior
> The compiler should reject the program: Double[] is not convertible to 
> double[].
> h3. Notes
> Tested against master (commit: 8ba8e8264fc3edeb9c70b52937edb97b0246a5d5)
> Groovy 4.0.10 rejects the program as expected.



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

Reply via email to