You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/09/11 06:28:08 UTC

[27/50] logging-log4j2 git commit: LOG4J2-1349 bugfix when AsyncLoggerConfig ringbuffer MutableLogEvent initializes from a synchronous MutableLogEvent, it should not keep a reference to the other event's context data but should always copy the contents,

LOG4J2-1349 bugfix when AsyncLoggerConfig ringbuffer MutableLogEvent initializes from a synchronous MutableLogEvent, it should not keep a reference to the other event's context data but should always copy the contents, since the events and their context data object are accessed and modified in different threads


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/f2818eb6
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/f2818eb6
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/f2818eb6

Branch: refs/heads/master
Commit: f2818eb6bf517e6b3e394e37b8a188ab57061981
Parents: 4882847
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 2 23:24:52 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 2 23:24:52 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/impl/MutableLogEvent.java  | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/f2818eb6/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
index bcdc40d..97cb5d6 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MutableLogEvent.java
@@ -89,11 +89,12 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         this.timeMillis = event.getTimeMillis();
         this.thrown = event.getThrown();
         this.thrownProxy = event.getThrownProxy();
-        if (event.getContextData() instanceof MutableContextData) {
-            this.contextData = (MutableContextData) event.getContextData();
-        } else {
-            this.contextData.putAll(event.getContextData());
-        }
+
+        // NOTE: this ringbuffer event SHOULD NOT keep a reference to the specified
+        // thread-local MutableLogEvent's context data, because then two threads would call
+        // ContextData.clear() on the same shared instance, resulting in data corruption.
+        this.contextData.putAll(event.getContextData());
+
         this.contextStack = event.getContextStack();
         this.source = event.isIncludeLocation() ? event.getSource() : null;
         this.threadId = event.getThreadId();