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/02 14:33:09 UTC

logging-log4j2 git commit: LOG4J2-1010&LOG4J2-1447 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 conten

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure 2a976a990 -> 48f7553c0


LOG4J2-1010&LOG4J2-1447 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/48f7553c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/48f7553c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/48f7553c

Branch: refs/heads/LOG4J2-1010&LOG4J2-1447-injectable-contextdata&better-datastructure
Commit: 48f7553c0765aca5eaf9ba90a93ee395d24b1126
Parents: 2a976a9
Author: rpopma <rp...@apache.org>
Authored: Fri Sep 2 23:33:00 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Sep 2 23:33:00 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/48f7553c/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 08423c6..366216e 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
@@ -88,11 +88,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();