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/03/14 17:10:33 UTC

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

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 <rp...@apache.org>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <rp...@apache.org>
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 {


Re: 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

Posted by Gary Gregory <ga...@gmail.com>.
In this given case, checkstyle or not, IMO the 'sin' was that the number
was hardcoded twice ;-)

On Mon, Mar 14, 2016 at 9:42 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> Yeah - they generate checkstyle errors. Not that we seem to pay much
> attention to the checkstyle report ;-)
>
> Ralph
>
> On Mar 14, 2016, at 9:17 AM, Gary Gregory <ga...@gmail.com> wrote:
>
> Magic numbers need to be refactored to a static IMO.
>
> Gary
> ---------- Forwarded message ----------
> From: <rp...@apache.org>
> 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: commits@logging.apache.org
>
>
> 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 <rp...@apache.org>
> Authored: Tue Mar 15 03:10:31 2016 +1100
> Committer: rpopma <rp...@apache.org>
> 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: garydgregory@gmail.com | ggregory@apache.org
> 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
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
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

Re: 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

Posted by Ralph Goers <ra...@dslextreme.com>.
Yeah - they generate checkstyle errors. Not that we seem to pay much attention to the checkstyle report ;-)

Ralph

> On Mar 14, 2016, at 9:17 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> Magic numbers need to be refactored to a static IMO.
> 
> Gary
> ---------- Forwarded message ----------
> From: <rpopma@apache.org <ma...@apache.org>>
> 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: commits@logging.apache.org <ma...@logging.apache.org>
> 
> 
> 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 <http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo>
> Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/69999c22 <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 <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 <http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/69999c22>
> 
> Branch: refs/heads/master
> Commit: 69999c2278bbefdace942ea5de9683226c14b5fe
> Parents: 05adeef
> Author: rpopma <rpopma@apache.org <ma...@apache.org>>
> Authored: Tue Mar 15 03:10:31 2016 +1100
> Committer: rpopma <rpopma@apache.org <ma...@apache.org>>
> 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 <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: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
> 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 <http://garygregory.wordpress.com/> 
> Home: http://garygregory.com/ <http://garygregory.com/>
> Tweet! http://twitter.com/GaryGregory <http://twitter.com/GaryGregory>

Fwd: 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

Posted by Gary Gregory <ga...@gmail.com>.
Magic numbers need to be refactored to a static IMO.

Gary
---------- Forwarded message ----------
From: <rp...@apache.org>
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: commits@logging.apache.org


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 <rp...@apache.org>
Authored: Tue Mar 15 03:10:31 2016 +1100
Committer: rpopma <rp...@apache.org>
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: garydgregory@gmail.com | ggregory@apache.org
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