You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2015/06/23 18:14:47 UTC

logging-log4j2 git commit: [LOG4J2-1067] ThrowableProxy getExtendedStackTraceAsString throws NPE on deserialized nested exceptions.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 7d732fa7a -> 4786a7395


[LOG4J2-1067] ThrowableProxy getExtendedStackTraceAsString throws NPE on
deserialized nested exceptions.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4786a739
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4786a739
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4786a739

Branch: refs/heads/master
Commit: 4786a7395121e0fd1b4e12d7e1b3c0eebd64d794
Parents: 7d732fa
Author: ggregory <gg...@apache.org>
Authored: Tue Jun 23 09:14:45 2015 -0700
Committer: ggregory <gg...@apache.org>
Committed: Tue Jun 23 09:14:45 2015 -0700

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ThrowableProxy.java | 18 ++++++------
 .../log4j/core/impl/ThrowableProxyTest.java     | 29 +++++++++++++++++++-
 src/changes/changes.xml                         |  3 ++
 3 files changed, 40 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4786a739/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
index 67d55ec..d0800cc 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
@@ -202,15 +202,15 @@ public class ThrowableProxy implements Serializable {
     }
 
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
-    private void formatCause(final StringBuilder sb, final ThrowableProxy cause, final List<String> ignorePackages) {
-        if (cause == null) {
-            return;
-        }
-        sb.append("Caused by: ").append(cause).append(EOL);
-        this.formatElements(sb, cause.commonElementCount, cause.getThrowable().getStackTrace(),
-                cause.extendedStackTrace, ignorePackages);
-        this.formatCause(sb, cause.causeProxy, ignorePackages);
-    }
+	private void formatCause(final StringBuilder sb, final ThrowableProxy cause, final List<String> ignorePackages) {
+		if (cause == null) {
+			return;
+		}
+		sb.append("Caused by: ").append(cause).append(EOL);
+		this.formatElements(sb, cause.commonElementCount, cause.getStackTrace(), cause.extendedStackTrace,
+				ignorePackages);
+		this.formatCause(sb, cause.causeProxy, ignorePackages);
+	}
 
     private void formatElements(final StringBuilder sb, final int commonCount, final StackTraceElement[] causedTrace,
             final ExtendedStackTraceElement[] extStackTrace, final List<String> ignorePackages) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4786a739/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
index 7019aa2..08d0a4b 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/impl/ThrowableProxyTest.java
@@ -35,7 +35,6 @@ import javax.xml.bind.DatatypeConverter;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -146,6 +145,34 @@ public class ThrowableProxyTest {
 
         assertEquals(proxy.getExtendedStackTraceAsString(), proxy2.getExtendedStackTraceAsString());
     }
+    
+    @Test
+	public void testSerialization_getExtendedStackTraceAsStringWithNestedThrowableDepth1() throws Exception {
+		final Throwable throwable = new RuntimeException(new IllegalArgumentException("This is a test"));
+		testSerialization_getExtendedStackTraceAsStringWithNestedThrowable(throwable);
+	}
+
+    @Test
+	public void testSerialization_getExtendedStackTraceAsStringWithNestedThrowableDepth2() throws Exception {
+		final Throwable throwable = new RuntimeException(
+				new IllegalArgumentException("This is a test", new IOException("level 2")));
+		testSerialization_getExtendedStackTraceAsStringWithNestedThrowable(throwable);
+	}
+
+    @Test
+	public void testSerialization_getExtendedStackTraceAsStringWithNestedThrowableDepth3() throws Exception {
+		final Throwable throwable = new RuntimeException(new IllegalArgumentException("level 1",
+				new IOException("level 2", new IllegalStateException("level 3"))));
+		testSerialization_getExtendedStackTraceAsStringWithNestedThrowable(throwable);
+	}
+
+    private void testSerialization_getExtendedStackTraceAsStringWithNestedThrowable(Throwable throwable) throws Exception {
+        final ThrowableProxy proxy = new ThrowableProxy(throwable);
+        final byte[] binary = serialize(proxy);
+        final ThrowableProxy proxy2 = deserialize(binary);
+
+        assertEquals(proxy.getExtendedStackTraceAsString(), proxy2.getExtendedStackTraceAsString());
+    }
 
     @Test
     public void testSerializationWithUnknownThrowable() throws Exception {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4786a739/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 5f66c22..3451f85 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,6 +48,9 @@
       <action issue="LOG4J2-1051" dev="ggregory" type="fix" due-to="Lukasz Lenart">
         NoClassDefFoundError when starting app on Google App Engine.
       </action>
+      <action issue="LOG4J2-1067" dev="ggregory" type="fix" due-to="Sam Braam">
+        ThrowableProxy getExtendedStackTraceAsString throws NPE on deserialized nested exceptions.
+      </action>
       <action issue="LOG4J2-1049" dev="rpopma" type="fix" due-to="Robert Schaft">
         AsyncAppender now resets the thread interrupted flag after catching InterruptedException.
       </action>