From 8367500593bc9060e77b0dd7910e7a56f1c55d9e Mon Sep 17 00:00:00 2001 From: Simon Kitching Date: Sat, 10 Nov 2007 17:40:43 +0000 Subject: [PATCH] Fix possible null-pointer exception when generating diagnostic messages. JIRA issue LOGGING-115. Thanks to Frantisek Jandos for the bugreport. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/logging/trunk@593798 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/logging/LogFactory.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/java/org/apache/commons/logging/LogFactory.java b/src/java/org/apache/commons/logging/LogFactory.java index a1b8a8f..13f8ea3 100644 --- a/src/java/org/apache/commons/logging/LogFactory.java +++ b/src/java/org/apache/commons/logging/LogFactory.java @@ -380,6 +380,14 @@ public abstract class LogFactory { // --------------------------------------------------------- Static Methods + /** Utility method to safely trim a string. */ + private static String trim(String src) { + if (src == null) { + return null; + } + return src.trim(); + } + /** *

Construct (if necessary) and return a LogFactory * instance, using the following ordered lookup procedure to determine @@ -499,7 +507,7 @@ public abstract class LogFactory { logDiagnostic( "[LOOKUP] A security exception occurred while trying to create an" + " instance of the custom factory class" - + ": [" + e.getMessage().trim() + + ": [" + trim(e.getMessage()) + "]. Trying alternative implementations..."); } ; // ignore @@ -513,7 +521,7 @@ public abstract class LogFactory { logDiagnostic( "[LOOKUP] An exception occurred while trying to create an" + " instance of the custom factory class" - + ": [" + e.getMessage().trim() + + ": [" + trim(e.getMessage()) + "] as specified by a system property."); } throw e; @@ -576,7 +584,7 @@ public abstract class LogFactory { logDiagnostic( "[LOOKUP] A security exception occurred while trying to create an" + " instance of the custom factory class" - + ": [" + ex.getMessage().trim() + + ": [" + trim(ex.getMessage()) + "]. Trying alternative implementations..."); } ; // ignore