Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.1-rc-3
-
None
-
None
-
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)