Message Boards

How to detect annotation existence

darkhck mr, modified 2 Years ago.

How to detect annotation existence

New Member Post: 1 Join Date: 9/22/21 Recent Posts

Hello everybody,

I have two bundle (MasterBundle and ChildBundle). MasterBundle contain a MasterPortlet and a CustomAnnotation with runtime policy.
In ChildBundle I have ChildPortlet wich extends MasterPortlet and contains some methods with CustomAnnotation.

In MasterPortlet I would like to check that my CustomAnnotation exists on method or not when I do some action.
method.isAnnotationPresent(CustomAnnotation.class) always return false

Annotation[] annotations = method.getAnnotations();
for(Annotation annotation : annotations) {
    Class annotationType = annotation.annotationType();
    Class customAnnotationClass = CustomAnnotation.class;
    if(annotationType.equals(CustomAnnotation.class)) {
        // unreachable part of code
    }
}

In this case I got the same interface, but the reference addresses are different. 
I think the problem is that every bundle has a classloader, but can I detect somehow that my CustomAnnotation exists on a method?

Thanks,