Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1067

ThrowableProxy getExtendedStackTraceAsString throws NPE on deserialized nested exceptions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.4
    • Component/s: Core
    • Labels:
      None

      Description

      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:

      ---
       .../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 {
      -- 
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              braam Sam Braam
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: