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/04/08 12:54:38 UTC

[2/5] logging-log4j2 git commit: LOG4J2-1343 synchronize on the ByteBufferDestination to protect against concurrent modification

LOG4J2-1343 synchronize on the ByteBufferDestination to protect against concurrent modification


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

Branch: refs/heads/master
Commit: acf8e3478e80b9222108ed6a428b9aa3cdc98a65
Parents: 19bafa4
Author: rpopma <rp...@apache.org>
Authored: Fri Apr 8 19:49:23 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Fri Apr 8 19:49:23 2016 +0900

----------------------------------------------------------------------
 .../log4j/core/layout/TextEncoderHelper.java    | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/acf8e347/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
index 698072d..3e59c8a 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/layout/TextEncoderHelper.java
@@ -51,11 +51,13 @@ public class TextEncoderHelper {
     }
 
     public void encodeText(final StringBuilder text, final ByteBufferDestination destination) {
-        try {
-            encodeText0(text, destination);
-        } catch (final Exception ex) {
-            logEncodeTextException(ex, text, destination);
-            encodeTextFallBack(text, destination);
+        synchronized (destination) {
+            try {
+                encodeText0(text, destination);
+            } catch (final Exception ex) {
+                logEncodeTextException(ex, text, destination);
+                encodeTextFallBack(text, destination);
+            }
         }
     }
 
@@ -98,9 +100,11 @@ public class TextEncoderHelper {
     }
 
     public void encodeText(final CharBuffer charBuf, final ByteBufferDestination destination) {
-        charsetEncoder.reset();
-        final ByteBuffer byteBuf = destination.getByteBuffer();
-        encode(charBuf, true, destination, byteBuf);
+        synchronized (destination) {
+            charsetEncoder.reset();
+            final ByteBuffer byteBuf = destination.getByteBuffer();
+            encode(charBuf, true, destination, byteBuf);
+        }
     }
 
     private ByteBuffer encode(final CharBuffer charBuf, final boolean endOfInput,