|
| 1 | +From 3c1ce68a548f435b63a104537b8653e5f14347a7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Razvan-Daniel Mihai < [email protected]> |
| 3 | +Date: Wed, 5 Nov 2025 12:27:34 +0100 |
| 4 | +Subject: fix: move StringBuffer into function to prevent race |
| 5 | + |
| 6 | +--- |
| 7 | + src/main/java/org/apache/log4j/xml/XMLLayout.java | 10 +--------- |
| 8 | + 1 file changed, 1 insertion(+), 9 deletions(-) |
| 9 | + |
| 10 | +diff --git a/src/main/java/org/apache/log4j/xml/XMLLayout.java b/src/main/java/org/apache/log4j/xml/XMLLayout.java |
| 11 | +index 4f0d99f3..157ecdc6 100644 |
| 12 | +--- a/src/main/java/org/apache/log4j/xml/XMLLayout.java |
| 13 | ++++ b/src/main/java/org/apache/log4j/xml/XMLLayout.java |
| 14 | +@@ -64,9 +64,7 @@ import java.util.Arrays; |
| 15 | + public class XMLLayout extends Layout { |
| 16 | + |
| 17 | + private final int DEFAULT_SIZE = 256; |
| 18 | +- private final int UPPER_LIMIT = 2048; |
| 19 | + |
| 20 | +- private StringBuffer buf = new StringBuffer(DEFAULT_SIZE); |
| 21 | + private boolean locationInfo = false; |
| 22 | + private boolean properties = false; |
| 23 | + |
| 24 | +@@ -121,13 +119,7 @@ public class XMLLayout extends Layout { |
| 25 | + */ |
| 26 | + public String format(final LoggingEvent event) { |
| 27 | + |
| 28 | +- // Reset working buffer. If the buffer is too large, then we need a new |
| 29 | +- // one in order to avoid the penalty of creating a large array. |
| 30 | +- if (buf.capacity() > UPPER_LIMIT) { |
| 31 | +- buf = new StringBuffer(DEFAULT_SIZE); |
| 32 | +- } else { |
| 33 | +- buf.setLength(0); |
| 34 | +- } |
| 35 | ++ StringBuffer buf = new StringBuffer(DEFAULT_SIZE); |
| 36 | + |
| 37 | + // We yield to the \r\n heresy. |
| 38 | + |
0 commit comments