PicoContainer
  1. PicoContainer
  2. PICO-370

JNDIProvided unsafe handling of JNDIObjectReference.get may cause NPE

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.10
    • Fix Version/s: 2.11.1
    • Component/s: PicoContainer Gems
    • Labels:
      None
    • Number of attachments :
      2

      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];
      }
      
      1. JNDIProvided.patch
        2 kB
        Mathieu Rozieres
      2. JNDIProvided.patch
        2 kB
        Mathieu Rozieres

        People

        • Assignee:
          Paul Hammant
          Reporter:
          Mathieu Rozieres
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: