Bug 43599 - AsyncAppender fails on changing MessageObjects
Summary: AsyncAppender fails on changing MessageObjects
Status: RESOLVED FIXED
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Appender (show other bugs)
Version: 1.2
Hardware: All other
: P2 normal
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-11 06:02 UTC by Horst Scheruga
Modified: 2007-10-22 14:10 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Horst Scheruga 2007-10-11 06:02:43 UTC
If I use an AsyncAppender to log a message object that is changed after the call
of the logging method, the logging will sometime show up the value changed
afterwards.


Example

  StringBuffer buffer = new StringBuffer("Hello world");

  Logger.getLogger("sample").debug(buffer);

  buffer.setLength(0);
  buffer.append("changed message");

If an AsyncAppender is used for logging this,
it may log on of the three values:
  "Hello world"
  ""
  "changed message"
Comment 1 Curt Arnold 2007-10-22 14:10:32 UTC
Committed test and fix in rev 587252.

From reviewing the code, it appears that this bug has been in the log4j codebase for an extended time 
and was preserved (not introduced) in the AsyncAppender rewrite released in log4j 1.2.14.  Added a call to 
getRenderedMessage() which will capture the value of the message object before placing the LoggingEvent 
on the queue.