I have been using the Reflections lib to find all methods annotated with a specific annotation on some classes inside a dependency I have. The methods these dependencies provide are not being used, I just want to scan them for usage of an annotation.
Sample of my code:
public List<Method> searchClassesForMethodsAnnotatedWith(List<Class<?>> targetClasses, Class<? extends Annotation> annotation){
List<Method> filteredMethods = new ArrayList<>();
targetClasses.forEach((targetClass) -> {
Reflections temporaryReflections = new Reflections(targetClass.getName(), new MethodAnnotationsScanner());
Set<Method> foundMethods = temporaryReflections.getMethodsAnnotatedWith(annotation);
foundMethods.forEach((method) -> {
filteredMethods.add(method);
});
});
return filteredMethods;
}
The list of classes passed as an argument to the method was populated on another method, that looked inside the dependency for classes that had a specific extension.
Although, I am getting an exception back:
java.lang.NoClassDefFoundError: com/sun/star/uno/RuntimeException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at com.Statistics.Maestro_Running.MaestroParser.lambda$searchClassesForMethodsAnnotatedWith$1(MaestroParser.java:57)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at com.Statistics.Maestro_Running.MaestroParser.searchClassesForMethodsAnnotatedWith(MaestroParser.java:56)
at com.Statistics.Programs.compileDataFromMaestro(Programs.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: com.sun.star.uno.RuntimeException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 29 more
I don't understand how I was abled to look for extensions inside the classes, and I am receiving an error on checking for methods. What should I do?
Aucun commentaire:
Enregistrer un commentaire