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

fail to identify type error in static array initialization with generic classes

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Static Type Checker
    • None

    Description

      Probably related to GROOVY-9985

      import java.util.*
      
      class Test {
        public static void main(String[] args) {
          List<String> lst = ["fda"];
          List<Integer>[] x = new List<Integer>[]{lst};
          Integer k = x[0].get(0)
        }
      } 

      Actual behavior

      The program compiles but receiving the following runtime error:

       

      Exception in thread "main" org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'fda' with class 'java.lang.String' to class 'java.lang.Integer'
              at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:173)
              at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:288)
              at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:245)
              at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache(IndyInterface.java:336)
              at Test.main(test.groovy:7) 

      Expected behavior

      The program should have been rejected

      Attachments

        Activity

          People

            Unassigned Unassigned
            theosot Thodoris Sotiropoulos
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: