Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-11371

unsafe conversion of array of reference type to an array of primitive type

    XMLWordPrintableJSON

Details

    Description

      I have the following program

      class Test {
        public static void main(String[] args) {
          double[] z = new Double[]{null};
        }
      } 

      Actual behavior

      The compiler accepts the program. However, I get the following exception at runtime.

       

      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)
       

      Expected behavior

      The compiler should reject the program: Double[] is not convertible to double[].

      Notes

      Tested against master (commit: 8ba8e8264fc3edeb9c70b52937edb97b0246a5d5)

      Groovy 4.0.10 rejects the program as expected.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: