incubator-depot-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject svn commit: rev 10512 - incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/util
Date Mon, 03 May 2004 19:59:39 GMT
Author: ajack
Date: Mon May  3 12:59:38 2004
New Revision: 10512

Modified:
   incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/util/AntLogListener.java
Log:
Fixed NullPtr crash in Logging (was coding like Python ;-)


Modified: incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/util/AntLogListener.java
==============================================================================
--- incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/util/AntLogListener.java
(original)
+++ incubator/depot/trunk/version/src/java/org/apache/depot/version/ant/util/AntLogListener.java
Mon May  3 12:59:38 2004
@@ -41,44 +41,49 @@
 	public void log(int severity, Object message, Throwable thrower) {
 		int antSeverity = Project.MSG_ERR;
 
-		switch (severity) {
-			case LogConstants.DEBUG :
-				{
-					antSeverity = Project.MSG_DEBUG;
-					break;
-				}
-			case LogConstants.INFO :
-				{
-					antSeverity = Project.MSG_INFO;
-					break;
-				}
-			case LogConstants.VERBOSE :
-				{
-					antSeverity = Project.MSG_VERBOSE;
-					break;
-				}
-			case LogConstants.WARN :
-				{
-					antSeverity = Project.MSG_WARN;
-					break;
-				}
-			default :
-			case LogConstants.ERROR :
-				{
-					antSeverity = Project.MSG_ERR;
-					break;
-				}
-		}
-
-		StringBuffer messageStr = new StringBuffer(message.toString());
-
-		if (null != thrower) {
-			appendThrower(messageStr, thrower);
+		try {
 
+			switch (severity) {
+				case LogConstants.DEBUG :
+					{
+						antSeverity = Project.MSG_DEBUG;
+						break;
+					}
+				case LogConstants.INFO :
+					{
+						antSeverity = Project.MSG_INFO;
+						break;
+					}
+				case LogConstants.VERBOSE :
+					{
+						antSeverity = Project.MSG_VERBOSE;
+						break;
+					}
+				case LogConstants.WARN :
+					{
+						antSeverity = Project.MSG_WARN;
+						break;
+					}
+				default :
+				case LogConstants.ERROR :
+					{
+						antSeverity = Project.MSG_ERR;
+						break;
+					}
+			}
+
+			StringBuffer messageStr = new StringBuffer(message.toString());
+
+			if (null != thrower) {
+				appendThrower(messageStr, thrower);
+			}
+
+			m_component.log(messageStr.toString(), antSeverity);
+
+		} catch (Throwable t) {
+			m_component.log("Failed to log message : " + t.toString());
+			t.printStackTrace(System.err);
 		}
-
-		m_component.log(messageStr.toString(), antSeverity);
-
 	}
 
 	private void appendThrower(StringBuffer messageStr, Throwable thrower) {
@@ -86,14 +91,18 @@
 		messageStr.append(thrower.getLocalizedMessage());
 
 		StackTraceElement stacks[] = thrower.getStackTrace();
-		for (int i = 0; i < stacks.length; ++i) {
-			messageStr.append("\n");
-			messageStr.append(stacks[i].toString());
-		}
 
+		if (null != stacks)
+			for (int i = 0; i < stacks.length; ++i) {
+				messageStr.append("\n");
+				messageStr.append(stacks[i].toString());
+			}
+
+		// Note: not JDK 1.3, but I don't think we care
 		Throwable cause = thrower.getCause();
-		if (null != cause)
+		if (null != cause) {
 			messageStr.append("Cause: \n");
 			appendThrower(messageStr, cause);
+		}
 	}
 }

Mime
View raw message