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:18 UTC

[37/50] logging-log4j2 git commit: LOG4J2-1349 log event implementations should not try to modify shared copies of copy-on-write context data

LOG4J2-1349 log event implementations should not try to modify shared copies of copy-on-write context data


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

Branch: refs/heads/master
Commit: 189f87d138d9e7f7df05468c60a011f29298919e
Parents: 863cc12
Author: rpopma <rp...@apache.org>
Authored: Sun Sep 4 16:07:17 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Sep 4 16:07:17 2016 +0900

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/RingBufferLogEvent.java  | 8 +++++++-
 .../org/apache/logging/log4j/core/impl/Log4jLogEvent.java    | 7 ++++++-
 .../org/apache/logging/log4j/core/impl/MutableLogEvent.java  | 6 +++++-
 3 files changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/189f87d1/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index d20be14..423578c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -381,9 +381,15 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage, CharSequen
         this.message = null;
         this.thrown = null;
         this.thrownProxy = null;
-        this.contextData.clear();
         this.contextStack = null;
         this.location = null;
+        if (contextData != null) {
+            if (contextData.isFrozen()) { // came from CopyOnWrite thread context
+                contextData = null;
+            } else {
+                contextData.clear();
+            }
+        }
 
         trimMessageText();
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/189f87d1/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
index 8e152f3..19b7afd 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jLogEvent.java
@@ -132,8 +132,13 @@ public class Log4jLogEvent implements LogEvent {
                 if (other.getContextData() instanceof MutableContextData) {
                     this.contextData = (MutableContextData) other.getContextData();
                 } else {
-                    this.contextData.clear();
+                    if (this.contextData.isFrozen()) {
+                        this.contextData = ContextDataFactory.createContextData();
+                    } else {
+                        this.contextData.clear();
+                    }
                     this.contextData.putAll(other.getContextData());
+
                 }
                 this.thrownProxy = other.getThrownProxy();
                 this.source = other.getSource();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/189f87d1/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 97cb5d6..2a4f59b 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
@@ -120,7 +120,11 @@ public class MutableLogEvent implements LogEvent, ReusableMessage {
         thrownProxy = null;
         source = null;
         if (contextData != null) {
-            contextData.clear();
+            if (contextData.isFrozen()) { // came from CopyOnWrite thread context
+                contextData = null;
+            } else {
+                contextData.clear();
+            }
         }
         contextStack = null;