Magic numbers need to be refactored to a static IMO.

Gary
---------- Forwarded message ----------
From: <[email protected]>
Date: Mon, Mar 14, 2016 at 9:10 AM
Subject: logging-log4j2 git commit: LOG4J2-1296 trim reusable message
StringBuilder to 258 to ensure occasional very long messages do not result
in large char[] arrays being held by the RingBuffer forever
To: [email protected]


Repository: logging-log4j2
Updated Branches:
  refs/heads/master 05adeefad -> 69999c227


LOG4J2-1296 trim reusable message StringBuilder to 258 to ensure occasional
very long messages do not result in large char[] arrays being held by the
RingBuffer forever


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

Branch: refs/heads/master
Commit: 69999c2278bbefdace942ea5de9683226c14b5fe
Parents: 05adeef
Author: rpopma <[email protected]>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <[email protected]>
Committed: Tue Mar 15 03:10:31 2016 +1100

----------------------------------------------------------------------
 .../apache/logging/log4j/core/async/RingBufferLogEvent.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/69999c22/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 e918500..32d73d9 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
@@ -338,6 +338,12 @@ public class RingBufferLogEvent implements LogEvent {
                 null,
                 0, 0 // nanoTime
         );
+
+        // ensure that excessively long char[] arrays are not kept in
memory forever
+        if (messageText != null && messageText.length() > 258) { //
resized more than once from 128 (s=s*2+2)
+            messageText.setLength(258);
+            messageText.trimToSize();
+        }
     }

     private void writeObject(final java.io.ObjectOutputStream out) throws
IOException {




-- 
E-Mail: [email protected] | [email protected]
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Reply via email to