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

ThrowableProxy.getExtendedStackTraceAsString causes NullPointerException

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.1
    • 2.2
    • Core
    • None

    Description

      I'm trying to write a poc with Log4j 2.1, where distributed processes are logging to a remote server. The server is currently running the bundled TcpSocketServer.createSerializedSocketServer with a custom layout plugin.

      A process is logging an exception. I can then see in the custom layout plugin at the log server that the LogEvent doesn't contain a thrown, but that it contains a thrownProxy. So far so good. I'm then trying to get hold of a String representation of the message + stacktrace. I thought that I would be able to e.g invoke ThrowableProxy.getExtendedStackTraceAsString(), but that causes a NullPointerException since the throwable in the ThrowableProxy also is null after deserialization. Looks like ThrowableProxy assumes that throwable isn't null in a few methods.

      The exception that is logged by the client process is a simple new Exception("A message");

      The pom.xml that I'm using:

      <dependency>
      	<groupId>org.apache.logging.log4j</groupId>
      	<artifactId>log4j-api</artifactId>
      	<version>2.1</version>
      </dependency>
      <dependency>
      	<groupId>org.apache.logging.log4j</groupId>
      	<artifactId>log4j-core</artifactId>
      	<version>2.1</version>
      </dependency>
      <dependency>
      	<groupId>com.lmax</groupId>
      	<artifactId>disruptor</artifactId>
      	<version>3.3.0</version>
      </dependency>
      

      The stacktrace that I get in the server:

      2014-12-05 14:30:44,601 ERROR An exception occurred processing Appender XXXXX java.lang.NullPointerException
      	at org.apache.logging.log4j.core.impl.ThrowableProxy.getExtendedStackTraceAsString(ThrowableProxy.java:340)
      	at org.apache.logging.log4j.core.impl.ThrowableProxy.getExtendedStackTraceAsString(ThrowableProxy.java:323)
      

      Workaround:
      To invoke ThrowableProxy. getExtendedStackTrace() and format the stacktrace + message with my own format methods.

      Attachments

        Activity

          Kaj,

          Thank you for reporting this issue. I've committed a fix to Git master.

          Can you try with the current 2.2-SNAPSHOT build to confirm the fix and report back here?

          To get the snapshot, point maven to our snapshot repository here: https://repository.apache.org/content/repositories/snapshots

          You can also download the sources from Git and build locally.

          Thank you,
          Gary

          ggregory Gary D. Gregory added a comment - Kaj, Thank you for reporting this issue. I've committed a fix to Git master. Can you try with the current 2.2-SNAPSHOT build to confirm the fix and report back here? To get the snapshot, point maven to our snapshot repository here: https://repository.apache.org/content/repositories/snapshots You can also download the sources from Git and build locally. Thank you, Gary

          In Git master (see previous comment).

          ggregory Gary D. Gregory added a comment - In Git master (see previous comment).
          kajbj Kaj Bjurman added a comment -

          I'm within a network that isn't allowed to use your repo, but I downloaded the source for the latest revision of ThrowableProxy.java and tried that one as a path to 2.1. That worked, so this bug has been fixed.

          kajbj Kaj Bjurman added a comment - I'm within a network that isn't allowed to use your repo, but I downloaded the source for the latest revision of ThrowableProxy.java and tried that one as a path to 2.1. That worked, so this bug has been fixed.
          dimalinux Dmitry Holodov added a comment -

          Will 2.2 or any version with this fix be released soon? I'm running into this error too. The snapshot did fix it for me.

          I'm doing UDP logging. First I tried using the built in UdpSocketServer class, but it doesn't print the stack traces received since they are encapsulated in this ThrowableProxy. I wrote my own version of the UdpSocketServer to extract the stacktrace using ThrowableProxy. getExtendedStackTrace() and append it to the formatted message, but even that is failing with the bug in this ticket.

          Thanks!

          dimalinux Dmitry Holodov added a comment - Will 2.2 or any version with this fix be released soon? I'm running into this error too. The snapshot did fix it for me. I'm doing UDP logging. First I tried using the built in UdpSocketServer class, but it doesn't print the stack traces received since they are encapsulated in this ThrowableProxy. I wrote my own version of the UdpSocketServer to extract the stacktrace using ThrowableProxy. getExtendedStackTrace() and append it to the formatted message, but even that is failing with the bug in this ticket. Thanks!

          2.2 should be as soon as our RM is available. ralph.goers@dslextreme.com?

          ggregory Gary D. Gregory added a comment - 2.2 should be as soon as our RM is available. ralph.goers@dslextreme.com ?

          People

            ggregory Gary D. Gregory
            kajbj Kaj Bjurman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: