Christoph Eßer created CXF-5822:
-----------------------------------
Summary: NullPointerException in PropertiesLoaderUtils
Key: CXF-5822
URL: https://issues.apache.org/jira/browse/CXF-5822
Project: CXF
Issue Type: Bug
Components: Core
Affects Versions: 2.6.14
Reporter: Christoph Eßer
Priority: Critical
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:
{code:title=PropertiesLoaderUtils.java|borderStyle=solid}
/**
* 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);
...
{code}
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.
--
This message was sent by Atlassian JIRA
(v6.2#6252)