Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-5822

NullPointerException in PropertiesLoaderUtils

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.6.14
    • Fix Version/s: 2.6.15, 2.7.12, 3.0.1
    • Component/s: Core
    • Labels:
      None
    • Estimated Complexity:
      Moderate

      Description

      Under some circumstances in our project Thread.currentThread().getContextClasssLoader() is null. This leads to a NullPointerException when org.apache.cxf.common.util.PropertiesLoaderUtils.loadAllProperties() is called with that as an argument.

      This is the specific part of the code that contains the problem:

      PropertiesLoaderUtils.java
      /**
           * Load all properties from the given class path resource, using the given
           * class loader.
           * <p>
           * Merges properties if more than one resource of the same name found in the
           * class path.
           * 
           * @param resourceName the name of the class path resource
           * @param classLoader the ClassLoader to use for loading (or
           *            <code>null</code> to use the default class loader)
           * @return the populated Properties instance
           * @throws IOException if loading failed
           */
          public static Properties loadAllProperties(String resourceName, ClassLoader classLoader)
              throws IOException {
              return loadAllProperties(resourceName, classLoader, null, null, null);
          }        
          public static Properties loadAllProperties(String resourceName, ClassLoader classLoader,
                                                     Logger logger, Level level, String msg)
              throws IOException {
              Properties properties = new Properties();
              Enumeration<URL> urls = classLoader.getResources(resourceName);
      ...
      

      The Javadoc says that null is a valid value for this argument. However, the code does not check the variable for null and just calls classLoader.getResources(resourceName). This check should be added and classLoader should be set to a reasonable value in case it is null. I will add a pull request for a fix of this issue later.

      Please note that we are bound to Java 1.5 in our project and thus switching to CXF 2.7 or 3.0 is not possible for us.

        Attachments

          Activity

            People

            • Assignee:
              sergey_beryozkin Sergey Beryozkin
              Reporter:
              cehser Christoph E├čer
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: