From a2fc70daffd63bad6ab9daa85f425e780683f3c8 Mon Sep 17 00:00:00 2001
From: Adrian Crum
Date: Sat, 18 Apr 2015 08:30:03 +0000
Subject: [PATCH] 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
---
framework/base/src/org/ofbiz/base/util/Debug.java | 8 ++++++--
.../base/src/org/ofbiz/base/util/UtilProperties.java | 9 +++++----
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/framework/base/src/org/ofbiz/base/util/Debug.java b/framework/base/src/org/ofbiz/base/util/Debug.java
index 8e7fb3b700..ebe7a5fff2 100644
--- a/framework/base/src/org/ofbiz/base/util/Debug.java
+++ b/framework/base/src/org/ofbiz/base/util/Debug.java
@@ -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");
}
}
diff --git a/framework/base/src/org/ofbiz/base/util/UtilProperties.java b/framework/base/src/org/ofbiz/base/util/UtilProperties.java
index 655adbd563..0c48c16480 100644
--- a/framework/base/src/org/ofbiz/base/util/UtilProperties.java
+++ b/framework/base/src/org/ofbiz/base/util/UtilProperties.java
@@ -287,9 +287,10 @@ public class UtilProperties implements Serializable {
* properties files before OFBiz has been fully initialized.
*
* @param fileName The full name of the properties file ("foo.properties")
- * @return A new Properties instance created from fileName
+ * @return A new Properties instance created from fileName, or
+ * null if the file was not found
* @throws IllegalArgumentException if fileName 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 {