vancetang / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Null.Pointer.Exception #83

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1a. Create a project and a single package containing the attached file 
ClasseAnotada.
1b. Create another project containing the attached Annotations files.
1c. Make project from 1a depend on project 1b. to be able to use the annotations

2. From a 3rd project running in a different classpath, with dependency to the 
1b project:

URLClassLoader classLoader = URLClassLoader.newInstance(new 
URL[]{"PATH_TO_THE_1A_JAR_FILE"});

new Reflections(new ConfigurationBuilder().setScanners(new 
MethodAnnotationsScanner(), new 
MethodParametersAnnotationsScanner()).setUrls(ClasspathHelper.forClass(classLoad
er.loadClass("<PACKAGE_NAME>.ClasseAnotada"), classLoader))); 

Set<Method> methods = reflections.getMethodsAnnotatedWith(Action.class); 

3. This causes the following Null.pointer.exception

java.lang.NullPointerException
        at org.reflections.util.Utils.getMethodFromDescriptor(Utils.java:74)
        at org.reflections.Reflections.getMethodsAnnotatedWith(Reflections.java:402)

What is the expected output? What do you see instead?
Clearly the exoected result would be the annotated methods and I get the NPExc

What version of the product are you using? On what operating system?
0.9.5

Please provide any additional information below.

I've downloaded the code and I think the class instantiated from the method 
signature is null:

Class<?> aClass = ReflectionUtils.forName(className);
   ...
return aClass.getDeclaredMethod(methodName, parameterTypes);

Would be nice if I could get some feedback.
Thanks in advance,
Biasutti

Original issue reported on code.google.com by otavioal...@gmail.com on 8 Aug 2011 at 7:52

Attachments:

GoogleCodeExporter commented 9 years ago
The problem might be that there is no internal usage of the classloaders passed 
at the reflections contructor. It might be the case that only this classloader 
family is actually able to load the classes that are going to be scanned. 

Original comment by otavioal...@gmail.com on 8 Aug 2011 at 8:25

GoogleCodeExporter commented 9 years ago
Okay, now I see how I can do it! A little bit untrivial but ok!

ClasspathHelper.defaultClassLoaders = new ClassLoader[]{MY_CLASS_LOADER};

Original comment by otavioal...@gmail.com on 8 Aug 2011 at 8:42

GoogleCodeExporter commented 9 years ago
that's a nice workaround... version in trunk changed so that 
configurationBuilder.addClassLoader/setClassLoaders is now available to the 
getMethod/GetField methods, instead of changing the static field.

Original comment by ronm...@gmail.com on 30 Aug 2011 at 5:45