[
https://issues.apache.org/jira/browse/GROOVY-11371?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles resolved GROOVY-11371.
----------------------------------
Fix Version/s: 5.0.0-alpha-10
Resolution: Fixed
https://github.com/apache/groovy/commit/08e1e8d5903db572283abd0f514f05ec60757f58
If conversion is still desired, explicit coerce can be used:
{code:groovy}
@TypeChecked test(Integer[] integers) {
int[] ints = (integers as int[])
}
test(new Integer[]{1,2,3})
{code}
> 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
> Fix For: 5.0.0-alpha-10
>
>
> 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)