[prev in list] [next in list] [prev in thread] [next in thread]
List: log4j-dev
Subject: svn commit: r738488 - in /logging/log4j/trunk: src/changes/changes.xml
From: carnold () apache ! org
Date: 2009-01-28 13:55:54
Message-ID: 20090128135554.7EB4D23888AF () eris ! apache ! org
[Download RAW message or body]
Author: carnold
Date: Wed Jan 28 13:55:53 2009
New Revision: 738488
URL: http://svn.apache.org/viewvc?rev=738488&view=rev
Log:
Bug 44038: log4j is susceptible to exception during Exception.printStackTrace
Modified:
logging/log4j/trunk/src/changes/changes.xml
logging/log4j/trunk/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java
logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java
Modified: logging/log4j/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/changes/changes.xml?rev=738488&r1=738487&r2=738488&view=diff
==============================================================================
--- logging/log4j/trunk/src/changes/changes.xml (original)
+++ logging/log4j/trunk/src/changes/changes.xml Wed Jan 28 13:55:53 2009
@@ -75,6 +75,7 @@
<action action="fix" issue="46163">LoggerDynamicMBean needs to handle a null \
Appender name.</action>
<action action="fix" issue="45704">DOMConfigurator.configure(URL) fails on \
JRE 1.5.0_16.</action>
<action action="add" issue="44357">Document system properties used by \
log4j.</action> + <action action="fix" issue="44038">log4j is susceptible to \
exceptions in Exception.printStackTrace.</action> </release>
Modified: logging/log4j/trunk/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java?rev=738488&r1=738487&r2=738488&view=diff
==============================================================================
--- logging/log4j/trunk/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java \
(original)
+++ logging/log4j/trunk/src/main/java/org/apache/log4j/DefaultThrowableRenderer.java \
Wed Jan 28 13:55:53 2009 @@ -56,7 +56,10 @@
public static String[] render(final Throwable throwable) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
- throwable.printStackTrace(pw);
+ try {
+ throwable.printStackTrace(pw);
+ } catch(RuntimeException ex) {
+ }
pw.flush();
LineNumberReader reader = new LineNumberReader(
new StringReader(sw.toString()));
Modified: logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java?rev=738488&r1=738487&r2=738488&view=diff
==============================================================================
--- logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java \
(original)
+++ logging/log4j/trunk/tests/src/java/org/apache/log4j/spi/ThrowableInformationTest.java \
Wed Jan 28 13:55:53 2009 @@ -299,4 +299,39 @@
String[] rep2 = ti.getThrowableStrRep();
assertEquals("Hello, World", rep2[0]);
}
+
+ /**
+ * Custom throwable that throws a runtime exception
+ * when printStackTrace is called.
+ */
+ private static final class NastyThrowable extends Throwable {
+ /**
+ * Create new instance.
+ */
+ public NastyThrowable() {
+ }
+
+ /**
+ * Print stack trace.
+ *
+ * @param s print writer.
+ */
+ public void printStackTrace(final PrintWriter s) {
+ s.print("NastyException");
+ throw new RuntimeException("Intentional exception");
+ }
+ }
+
+ /**
+ * Tests that a failure in printStackTrace
+ * does not percolate out of getThrowableStrRep().
+ *
+ */
+ public void testNastyException() {
+ ThrowableInformation ti = new ThrowableInformation(
+ new NastyThrowable());
+ String[] rep = ti.getThrowableStrRep();
+ assertEquals("NastyException", rep[0]);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic