Details
-
Type: Bug
-
Status: Resolved
-
Priority: Minor
-
Resolution: Fixed
-
Affects Version/s: 2.10
-
Fix Version/s: 2.11.1
-
Component/s: PicoContainer Gems
-
Labels:None
-
Number of attachments :
Description
JNDIObjectReference.get return a null value if the JNDI lookup failed with a NameNotFoundException. (JNDIObjectReference.java:51-62 in my 2.10.2 sources jar ).
There are two possible NPE regarding this behaviour in JNDIProvided class. Here are the code snipped :
public JNDIProvided(final JNDIObjectReference<T> reference) { this(reference.get().getClass(),reference); }
// JNDIObjectReference<T> jndiReference; public Class<? extends T> getComponentImplementation() { return (Class<? extends T>) jndiReference.get().getClass(); }
A solution can be to write the following method inside JNDIObjectReference and to call it instead of getting the class of the context.lookup result (moreover it may saves some JNDI lookup too)
public Class<?> returnedClass { ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperClass(); return (Class) parameterizedtype.getActualTypeArguments()[0]; }
Just a detail, because of Generic Type erasure, the solution proposed is not working. The only way i found was to modify JNDIObjectReference constructors and add a Class<? extends T> parameter that i return inside a getClazz() function for JNDIProvided.