Taisuke Tashiro created LOG4J2-2368:
---------------------------------------
Summary: Outputs wrong message when used within overridden
Throwable method
Key: LOG4J2-2368
URL: https://issues.apache.org/jira/browse/LOG4J2-2368
Project: Log4j 2
Issue Type: Bug
Components: Core
Affects Versions: 2.11.0, 2.8.1
Reporter: Taisuke Tashiro
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.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)