Sam Braam created LOG4J2-1067:
---------------------------------
Summary: ThrowableProxy getExtendedStackTraceAsString throws NPE
on deserialized nested exceptions
Key: LOG4J2-1067
URL: https://issues.apache.org/jira/browse/LOG4J2-1067
Project: Log4j 2
Issue Type: Bug
Components: Core
Affects Versions: 2.3
Reporter: Sam Braam
Priority: Minor
Fix For: 2.4
In a similar vein to LOG4J2-914, I also am attempting to use log4j as a daemon
log server. The fix for LOG4J2-914 only solved the NPE problem for one
dimensional exceptions. Nested exceptions also cause an NPE in the current
implementation. Here is a test/patch diff for the bug:
{code}
---
.../org/apache/logging/log4j/core/impl/ThrowableProxy.java | 2 +-
.../org/apache/logging/log4j/core/impl/ThrowableProxyTest.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
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..307de58 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
@@ -207,7 +207,7 @@ public class ThrowableProxy implements Serializable {
return;
}
sb.append("Caused by: ").append(cause).append(EOL);
- this.formatElements(sb, cause.commonElementCount,
cause.getThrowable().getStackTrace(),
+ this.formatElements(sb, cause.commonElementCount,
cause.getStackTrace(),
cause.extendedStackTrace, ignorePackages);
this.formatCause(sb, cause.causeProxy, ignorePackages);
}
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..6eb5dbc 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
@@ -146,6 +146,16 @@ public class ThrowableProxyTest {
assertEquals(proxy.getExtendedStackTraceAsString(),
proxy2.getExtendedStackTraceAsString());
}
+
+ @Test
+ public void
testSerialization_getExtendedStackTraceAsStringWithNestedThrowable() throws
Exception {
+ final Throwable throwable = new RuntimeException(new
IllegalArgumentException("This is a test"));
+ 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 {
--
{code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]