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

Outputs wrong message when used within overridden Throwable method

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.8.1, 2.11.0
    • 2.11.1, 3.0.0
    • Core
    • None

    Description

      When a message A is logged with Throwable object and if message B is logged within the Throwable object's method, message A is lost and message B is logged instead.

      Following is a code example to recreate the issue:

      Logger loggerA = LogManager.getLogger("A");
      Logger loggerB = LogManager.getLogger("B");
      Throwable throwable =
          new Throwable() {
              public String getMessage() {
                  loggerB.debug("MESSAGE B");
                  return "message";
      {{        }}}
          };
      loggerA.debug("MESSEGE A", throwable);

      "MESSAGE A" should be logged to loggerA but "MESSAGE B" is logged instead.

      Cause of this problem is reuse of StringBuilder instance within the execution thread in org.apache.logging.log4j.core.layout.AbstractStringLayout class. While processing loggerA, getMessage() is called by org.apache.logging.log4j.core.impl.ThrowableProxy to obtain throwable object information and the content of StringBuilder is changed by loggerB.

       

       

       

      Attachments

        Issue Links

          Activity

            People

              ckozak Carter Kozak
              Tai Tash Taisuke Tashiro
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: