Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.5.6
-
Fix Version/s: 1.7-beta-1
-
Component/s: bytecode, class generator, command line processing
-
Labels:None
-
Number of attachments :1
Description
I want to use annotated classes im my Groovy beans, but org.springframework.scripting.groovy.GroovyScriptFactory#getScriptedObject uses getGroovyClassLoader().parseClass call, and it returns class instance with no annotations attached.
The same groovy
-
Hide
- groovy-2982-testcase.zip
- 31/Jul/08 7:57 AM
- 13 kB
- Max Ishchenko
-
- groovy-2982/conf/contextPrecompiled.xml 0.5 kB
- groovy-2982/conf/contextRuntime.xml 0.6 kB
- groovy-2982/groovy.iml 0.6 kB
- groovy-2982/groovy.ipr 29 kB
- groovy-2982/out/.../SampleAnnotation.class 0.3 kB
- groovy-2982/.../TestGroovyBeanAnnotationPresent.class 1 kB
- groovy-2982/out/.../TestPrecompiled.class 0.6 kB
- groovy-2982/.../TestRuntimeCompilation.class 0.6 kB
- groovy-2982/.../AnnotatedGroovyClass.class 4 kB
- groovy-2982/.../AnnotatedGroovyClass.groovy 0.1 kB
- groovy-2982/src/.../SampleAnnotation.java 0.3 kB
- groovy-2982/.../TestGroovyBeanAnnotationPresent.java 0.9 kB
- groovy-2982/src/.../TestPrecompiled.java 0.4 kB
- groovy-2982/.../TestRuntimeCompilation.java 0.4 kB
Activity
But this not making much sense to me. class generation is the phase where the actual class is created. Without that part you won't get something to execute. The annotations are part of the generated class, thus the annotation processing must be part of the class generation or happen before that phase.
The only reason I could imagine that the annotation is lost, is that you execute two different versions of Groovy.
That's a testcase for the bug.
It includes Intellij Idea project for your convenience.
Run TestRuntimeCompilation and see that no annotations were generated in the bytecode
Run TestPrecompiled and see that the annotation is present in a class file.
The first testcase uses a GroovyScriptFactory for groovy bean definition, the second one uses precompiled groovy script put in classpath.
Of course, you must also put spring.jar, groovy-all.jar and commons-logging.jar into lib folder.
The testcase was run against groovy 1.5.6
But this seems to work:
def parsedClass = new GroovyClassLoader().parseClass('@Deprecated class Foo {}', 'Foo') println parsedClass.annotations.size() // => 1 @Deprecated class Bar {} println Bar.annotations.size() // => 1
is the class we test in the provided test case really the groovy class, or is it some kind of proxy?
Sorry, pressed "add" accidentally.
So, the same groovy file compiled with groovyc generated bytecode WITH annotations.
After some investigation I found, that groovy.lang.GroovyClassLoader#parseClass method invokes
int goalPhase = compile(Phases.CLASS_GENERATION),
unit.compile(goalPhase);
whereas FileSystemCompiler invokes unit.compile(), and it invokes compile((Phases.ALL)
The annotation is present in AST in both cases. But it is lost when goalPhase = Phases.CLASS_GENERATION