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

Incorrect parameter for annotations throws compilation exception with obfuscated message

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.1-rc-3
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None
    • Environment:
      JDK 1.6, Vista

      Description

      Test class below. The problem is simple, and it should have been found immediately on compilation. Instead, a completely cryptic message is given from the exception thrown from the AnnotationVisitor:

      "java.lang.ClassCastException: org.codehaus.groovy.ast.expr.VariableExpression cannot be cast to org.codehaus.groovy.ast.expr.PropertyExpression"

      Expected behavior (best case) should give the file name, annotation, and line number of the offense. In Grails this problem is especially bad because the stack traces are exceptionally long making this even more difficult to deal with.

      The following class will cause this issue, when compiled:

      import javax.persistence.*

      @Entity
      class Foo{

      @Id
      @GeneratedValue
      long id

      @Temporal(DATE)
      Date testDate
      }

      When compiled it will produce this stack trace (to avoid the stack trace, change DATE above to TemporalType.DATE):

      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, General error during class generation: org.codehaus.groovy.ast.expr.VariableExpression cannot be cast to org.codehaus.groovy.ast.expr.PropertyExpression

      java.lang.ClassCastException: org.codehaus.groovy.ast.expr.VariableExpression cannot be cast to org.codehaus.groovy.ast.expr.PropertyExpression
      at org.codehaus.groovy.classgen.AnnotationVisitor.visitExpression(AnnotationVisitor.java:137)
      at org.codehaus.groovy.classgen.AnnotationVisitor.visit(AnnotationVisitor.java:97)
      at org.codehaus.groovy.classgen.ExtendedVerifier.visitAnnotation(ExtendedVerifier.java:108)
      at org.codehaus.groovy.classgen.ExtendedVerifier.visitAnnotations(ExtendedVerifier.java:90)
      at org.codehaus.groovy.classgen.ExtendedVerifier.visitField(ExtendedVerifier.java:59)
      at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:842)
      at org.codehaus.groovy.classgen.ExtendedVerifier.visitClass(ExtendedVerifier.java:51)
      at org.codehaus.groovy.control.CompilationUnit$10.call(CompilationUnit.java:669)
      at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:8
      85)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:436)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:417)
      at org.codehaus.groovy.tools.FileSystemCompiler.compile(FileSystemCompiler.java:56)
      at org.codehaus.groovy.tools.FileSystemCompiler.main(FileSystemCompiler.java:220)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:101)
      at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)

        Attachments

          Activity

            People

            • Assignee:
              alexpopescu Alexandru Popescu
              Reporter:
              hippyod Evan Slatis
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: