duplicate annotation entries when running with Java8u45

18 views
Skip to first unread message

davide.s...@gmail.com

unread,
Apr 17, 2015, 11:14:27 AM4/17/15
to google-code...@googlegroups.com
Hi,
I am using reflections 0.9.9 to have a list of all methods annotated with a given annotation.
I have done this in my projects without problems using Java6 and Java7, but if I use Java8 (jdk8u45) I get duplicate hits in case my annotated methods are implementation of abstract methods.
Here an example.

public abstract class AbstractHandler<T extends BeanInterface> {
  abstract protected void myMethod(T bean);
}


public class HandlerImplementation extends AbstractHandler<BeanImplementation> {

  @MyAnnotation
  protected void myMethod(BeanImplementation bean){
    ...
  }
}

When I scan to find all the methods annotated with MyAnnotation I get two hits:
- HandlerImplementation.myMethod(BeanImplementation)
- HandlerImplementation.myMethod(BeanInterface)
The method in the abstract class is not even annotated.

Here the piece of code where I was able to reproduce this behavior:


AbstractScanner methodScanner = new MethodAnnotationsScanner();
Predicate<String> filter = new FilterBuilder().include(FilterBuilder.prefix(HandlerImplementationName));

ConfigurationBuilder configuration = new ConfigurationBuilder();
configuration.filterInputsBy(filter);
configuration.setUrls(ClasspathHelper.forClassLoader(classLoader));
configuration.setMetadataAdapter(new JavassistAdapter());
configuration.setScanners(methodScanner);
configuration.addClassLoader(classLoader);

Reflections reflections = new Reflections(configuration);

Collection<String> collection = methodScanner.getStore().get(MyAnnotatioName);

Anybody has experienced the same or have any hints?

Thanks!
Davide
Reply all
Reply to author
Forward
0 new messages