Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-953

Bundle#loadClass sometimes return null instead of throwing a CNFE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • framework-1.6.0
    • Framework
    • None

    Description

      Here is a patch:

      Index: src/main/java/org/apache/felix/framework/Felix.java
      ===================================================================
      --- src/main/java/org/apache/felix/framework/Felix.java (revision 746347)
      +++ src/main/java/org/apache/felix/framework/Felix.java (working copy)
      @@ -1338,7 +1338,12 @@
                       throw new ClassNotFoundException(name, ex);
                   }
               }
      -        return bundle.getCurrentModule().getClassByDelegation(name);
      +        Class clazz = bundle.getCurrentModule().getClassByDelegation(name);
      +        if (clazz == null)
      +        {
      +            throw new ClassNotFoundException(name);
      +        }
      +        return clazz;
           }
       
           /**
      

      I'm wondering if there any reason why ModuleImpl#getClassByDelegation(String) returns null instead of throwing a NPE.
      Browsing through the code, it seems there are several places where a null value is checked, then a CNFE thrown.
      This would also avoid possible NPE in felix code as in Felix#createBundleActivator.

      I think it would be nice to iron the definition of IModule#getClassByDelegation to either remove the thrown CNFE or never returns null, as currently both can happen.
      The IWire interface has exactly the same problem.

      I will try to come up with a patch which will never return a null value for both interfaces.

      Attachments

        1. FELIX-953.patch
          1 kB
          Guillaume Nodet

        Issue Links

          Activity

            People

              rickhall Richard S. Hall
              gnodet Guillaume Nodet
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: