I'm experiencing a strange behaviour when looking via reflection for annotations on a method belonging to a class proxied via CGLIB. We use CGLIB in Spring, and if I annotate a method only with an annotation it works well (I'm able to retrieve the annotations via the getAnnotations()
method on the correspondent Method
object). If I annotate the method with 2 annotations instead (no matter the order of annotation), getAnnotations()
just return null
. Both annotation have RetentionPolicy.RUNTIME
.
I read there are some issues with CGLIB, but it's strange that it simply works for one annotation and it returns null when I put 2 annotations.
Any suggestions?
(Using Spring 3.0.5 and CGLIB 2.2.2)
Adding code:
1st annotation is:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Produces {
ResultType[] value();
}
2nd annotation is
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface JamonMonitored {
String type() default "";
String tag() default "";
}
And the block of code is for checking annotations is
Collection<Method> candidates = Collections2.filter(Arrays.asList(executorInstance.getClass().getMethods()), new Predicate<Method>() {
@Override
public boolean apply(Method input) {
return input.getAnnotation(Produces.class) != null;
}
});
if (candidates.isEmpty()) {
// throws exception
}
If I annotate a method with both @Produces and @JamonMonitored, getAnnotation(Produces.class)
is always null
.