A small change to the behavior of the UtilProperties.createProperties() method: if the file is not found, return null instead of throwing an exception.

https://issues.apache.org/jira/browse/OFBIZ-6261

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1674453 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Adrian Crum
2015-04-18 08:30:03 +00:00
parent e55e71edcc
commit a2fc70daff
2 changed files with 11 additions and 6 deletions
@@ -66,8 +66,12 @@ public final class Debug {
// initialize levelOnCache
Properties properties = UtilProperties.createProperties("debug.properties");
for (int i = 0; i < levelOnCache.length; i++) {
levelOnCache[i] = (i == Debug.ALWAYS || "true".equalsIgnoreCase(properties.getProperty(levelProps[i])));
if (properties != null) {
for (int i = 0; i < levelOnCache.length; i++) {
levelOnCache[i] = (i == Debug.ALWAYS || "true".equalsIgnoreCase(properties.getProperty(levelProps[i])));
}
} else {
throw new IllegalStateException("debug.properties file not found");
}
}
@@ -287,9 +287,10 @@ public class UtilProperties implements Serializable {
* properties files before OFBiz has been fully initialized.</p>
*
* @param fileName The full name of the properties file ("foo.properties")
* @return A new <code>Properties</code> instance created from <code>fileName</code>
* @return A new <code>Properties</code> instance created from <code>fileName</code>, or
* <code>null</code> if the file was not found
* @throws IllegalArgumentException if <code>fileName</code> is empty
* @throws IllegalStateException if there were any problems reading the file
* @throws IllegalStateException if there was a problem reading the file
*/
public static Properties createProperties(String fileName) {
Assert.notEmpty("fileName", fileName);
@@ -297,14 +298,14 @@ public class UtilProperties implements Serializable {
try {
URL url = Thread.currentThread().getContextClassLoader().getResource(fileName);
if (url == null) {
throw new IllegalStateException(fileName + " not found");
return null;
}
inStream = url.openStream();
Properties properties = new Properties();
properties.load(inStream);
return properties;
} catch (Exception e) {
throw new IllegalStateException("Exception thrown while reading debug.properties: " + e);
throw new IllegalStateException("Exception thrown while reading " + fileName + ": " + e);
} finally {
if (inStream != null) {
try {