Description
Same issue as below, my test class is:
@Qualifier @Retention(RUNTIME) @Target([FIELD, TYPE, METHOD]) public @interface MyAnnotation { MyValue value() }
Note: Did not import package for FIELD, TYPE and METHOD.
got the error below:
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.vmplugin.v5.Java5.configureAnnotationFromDefinition(Java5.java:227) at org.codehaus.groovy.vmplugin.v5.Java5.configureAnnotation(Java5.java:242) at org.codehaus.groovy.classgen.AnnotationVisitor.visit(AnnotationVisitor.java:81) at org.codehaus.groovy.classgen.ExtendedVerifier.visitAnnotation(ExtendedVerifier.java:154) at org.codehaus.groovy.classgen.ExtendedVerifier.visitAnnotations(ExtendedVerifier.java:115) at org.codehaus.groovy.classgen.ExtendedVerifier.visitClass(ExtendedVerifier.java:52) at org.codehaus.groovy.control.CompilationUnit$15.call(CompilationUnit.java:773) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:572) :services:easervices:groovydoc at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:550) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:527) :services:easervices:groovydoc UP-TO-DATE at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:506) at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:118) at org.gradle.api.internal.tasks.compile.ApiGroovyCompiler.execute(ApiGroovyCompiler.java:39) :common:persistence:persistence-utility:processResources at org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonServer.execute(CompilerDaemonServer.java:52) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(Reflectioch.java:35) at org.gradle.messaging.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.messaging.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:355) at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) :common:persistence:persistence-utility:processResources UP-TO-DATE at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724)
---- From original Jira
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)