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

@CompileStatic gives ClassCastException at runtime when calling methods on Object in some scenarios

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.3
    • 2.1.4
    • Static compilation
    • None
    • Windows 7, Java 6, Groovy 2.1.3

    Description

      Execute the following code, it will throw the exception. You can replace the values 1 and [] with any two incompatible types.

      MyClass.groovy
      @groovy.transform.CompileStatic class MyClass {
          public static void main(String[] args) {
              Object o = getObject()
              if(o == null) {
                  o = 1
              } else {
                  println o.toString()
              }
          }
      
          public static Object getObject() {
              ''
          }
      }
      

      Attachments

        Activity

          People

            melix Cédric Champeau
            bborchardt Brett Borchardt
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: