getAnnotation error?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

getAnnotation error?

Jason Cheatham


From: Jason Cheatham <[hidden email]>;
To: <[hidden email]>;
Subject: getAnnotation error?
Sent: Mon, Sep 24, 2012 6:07:25 PM

I'm using groovy eclipse 2.7.1 and I get the correct output with the first class and an error with the second. Is this an issue with Groovy?

import groovy.transform.CompileStatic;
import java.lang.reflect.Field;
@CompileStatic
class AnnotationCompileStatic {
public static boolean annotationCheck(Field field) {
Override annotation = field.getAnnotation(Override.class);
return (annotation != null);
}
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Output:
false
false
false
false
false
false
false

Copy same main method to a class in the same package and you get an error:

import java.lang.reflect.Field;
class AnnotationCompileStaticTest {
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Caught: java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
at AnnotationCompileStatic.annotationCheck(AnnotationCompileStatic.groovy:17)
at AnnotationCompileStatic$annotationCheck.call(Unknown Source)
at AnnotationCompileStaticTest$_main_closure1.doCall(AnnotationCompileStaticTest.groovy:11)
at AnnotationCompileStaticTest.main(AnnotationCompileStaticTest.groovy:10)
Reply | Threaded
Open this post in threaded view
|

Re: getAnnotation error?

Andrew Eisenberg
I can reproduce the problem inside of Eclipse.  I also tried on the command line with groovy 2.0.4 and I also see the problem.  When @CompileStatic is removed, the script runs as expected.

Based on the method signature that is being returned, it looks like the getAnnotation method is being searched for dynamically, but with the wrong return type.  So, this looks like an @CompileStatic bug.

I am cc-ing the groovy-user mailing list so that someone there can confirm.

On Mon, Sep 24, 2012 at 12:23 PM, Jason Cheatham <[hidden email]> wrote:


From: Jason Cheatham <[hidden email]>;
To: <[hidden email]>;
Subject: getAnnotation error?
Sent: Mon, Sep 24, 2012 6:07:25 PM

I'm using groovy eclipse 2.7.1 and I get the correct output with the first class and an error with the second. Is this an issue with Groovy?

import groovy.transform.CompileStatic;
import java.lang.reflect.Field;
@CompileStatic
class AnnotationCompileStatic {
public static boolean annotationCheck(Field field) {
Override annotation = field.getAnnotation(Override.class);
return (annotation != null);
}
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Output:
false
false
false
false
false
false
false

Copy same main method to a class in the same package and you get an error:

import java.lang.reflect.Field;
class AnnotationCompileStaticTest {
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Caught: java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
at AnnotationCompileStatic.annotationCheck(AnnotationCompileStatic.groovy:17)
at AnnotationCompileStatic$annotationCheck.call(Unknown Source)
at AnnotationCompileStaticTest$_main_closure1.doCall(AnnotationCompileStaticTest.groovy:11)
at AnnotationCompileStaticTest.main(AnnotationCompileStaticTest.groovy:10)

Reply | Threaded
Open this post in threaded view
|

Re: getAnnotation error?

Jason Cheatham
Thanks Andrew, have you heard anything new?
What's the best way to report the Field.getAnnotation() error with @CompileStatic?
Thanks,
Jason


From: Andrew Eisenberg <[hidden email]>
To: [hidden email]; user <[hidden email]>
Cc: Jason Cheatham <[hidden email]>
Sent: Monday, September 24, 2012 4:09 PM
Subject: Re: [groovy-eclipse-plugin-dev] getAnnotation error?

I can reproduce the problem inside of Eclipse.  I also tried on the command line with groovy 2.0.4 and I also see the problem.  When @CompileStatic is removed, the script runs as expected.

Based on the method signature that is being returned, it looks like the getAnnotation method is being searched for dynamically, but with the wrong return type.  So, this looks like an @CompileStatic bug.

I am cc-ing the groovy-user mailing list so that someone there can confirm.

On Mon, Sep 24, 2012 at 12:23 PM, Jason Cheatham <[hidden email]> wrote:


From: Jason Cheatham <[hidden email]>;
To: <[hidden email]>;
Subject: getAnnotation error?
Sent: Mon, Sep 24, 2012 6:07:25 PM

I'm using groovy eclipse 2.7.1 and I get the correct output with the first class and an error with the second. Is this an issue with Groovy?

import groovy.transform.CompileStatic;
import java.lang.reflect.Field;
@CompileStatic
class AnnotationCompileStatic {
public static boolean annotationCheck(Field field) {
Override annotation = field.getAnnotation(Override.class);
return (annotation != null);
}
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Output:
false
false
false
false
false
false
false

Copy same main method to a class in the same package and you get an error:

import java.lang.reflect.Field;
class AnnotationCompileStaticTest {
static main(args) {
String.class.declaredFields.each { Field field ->
println (AnnotationCompileStatic.annotationCheck(field) )
}
}
}
Caught: java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
java.lang.NoSuchMethodError: java.lang.reflect.Field.getAnnotation(Ljava/lang/Class;)Ljava/lang/Object;
at AnnotationCompileStatic.annotationCheck(AnnotationCompileStatic.groovy:17)
at AnnotationCompileStatic$annotationCheck.call(Unknown Source)
at AnnotationCompileStaticTest$_main_closure1.doCall(AnnotationCompileStaticTest.groovy:11)
at AnnotationCompileStaticTest.main(AnnotationCompileStaticTest.groovy:10)