You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ck...@apache.org on 2018/06/22 15:09:20 UTC

[1/2] logging-log4j2 git commit: [LOG4J2-2355] Add testing and changelog entry

Repository: logging-log4j2
Updated Branches:
  refs/heads/master f8113c029 -> 0fdf29de7


[LOG4J2-2355] Add testing and changelog entry

Remvoes logging to stderr when PropertiesUtil is presented with
a null key or value. This may occur in normal usage when keys are
removed from the properties map.


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

Branch: refs/heads/master
Commit: 0fdf29de784d1ec60357e3809c5df0a2de6c92dc
Parents: b0e5a13
Author: Carter Kozak <ck...@apache.org>
Authored: Fri Jun 22 11:05:52 2018 -0400
Committer: Carter Kozak <ck...@apache.org>
Committed: Fri Jun 22 11:09:04 2018 -0400

----------------------------------------------------------------------
 .../logging/log4j/util/PropertiesUtil.java      |  4 +---
 .../logging/log4j/util/PropertiesUtilTest.java  | 25 ++++++++++++++++----
 src/changes/changes.xml                         |  8 +++++++
 3 files changed, 30 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0fdf29de/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index f1c8f15..9349b2e 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -330,7 +330,7 @@ public final class PropertiesUtil {
                 source.forEach(new BiConsumer<String, String>() {
                     @Override
                     public void accept(final String key, final String value) {
-                        if (value != null) {
+                        if (key != null && value != null) {
                             literal.put(key, value);
                             final List<CharSequence> tokens = PropertySource.Util.tokenize(key);
                             if (tokens.isEmpty()) {
@@ -339,8 +339,6 @@ public final class PropertiesUtil {
                                 normalized.put(source.getNormalForm(tokens), value);
                                 tokenized.put(tokens, value);
                             }
-                        } else  {
-                            LowLevelLogUtil.log("Property " + key + " was skipped because of null value.");
                         }
                     }
                 });

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0fdf29de/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
index 574fbc1..49b62de 100644
--- a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
@@ -17,15 +17,17 @@
 
 package org.apache.logging.log4j.util;
 
+import org.junit.Before;
+import org.junit.Test;
+
 import java.nio.charset.Charset;
 import java.nio.charset.StandardCharsets;
 import java.util.Map;
 import java.util.Properties;
 
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 /**
  *
@@ -91,4 +93,19 @@ public class PropertiesUtilTest {
         Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8;
         assertEquals(expected, pu.getCharsetProperty("sun.err.encoding"));
     }
+
+    @Test
+    public void testNonStringSystemProperties() {
+        Object key1 = "1";
+        Object key2 = new Object();
+        System.getProperties().put(key1, new Object());
+        System.getProperties().put(key2, "value-2");
+        try {
+            final PropertiesUtil util = new PropertiesUtil(new Properties());
+            assertNull(util.getStringProperty("1"));
+        } finally {
+            System.getProperties().remove(key1);
+            System.getProperties().remove(key2);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0fdf29de/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 35a42a1..b027bd4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -187,6 +187,10 @@
         RingBufferLogEvent memento messages provide the expected format string, and no longer attempt to substitute parameters into curly braces in parameter toString values.
         Both RingBufferLogEvent and MutableLogEvent memento implementations memoize results to avoid rebuilding formatted string values.
       </action>
+      <action issue="LOG4J2-2355" dev="ckozak" type="fix" due-to="Henrik Brautaset Aronsen">
+        PropertiesUtil ignores non-string system properties. Fixes a NoClassDefFoundError initializing StatusLogger
+        caused by an NPE while initializing the static PropertiesUtil field.
+      </action>
     </release>
     <release version="2.11.1" date="2018-MM-DD" description="GA Release 2.11.1">
       <action issue="LOG4J2-2268" dev="rgoers" type="fix" due-to="Tilman Hausherr">
@@ -267,6 +271,10 @@
         RingBufferLogEvent memento messages provide the expected format string, and no longer attempt to substitute parameters into curly braces in parameter toString values.
         Both RingBufferLogEvent and MutableLogEvent memento implementations memoize results to avoid rebuilding formatted string values.
       </action>
+      <action issue="LOG4J2-2355" dev="ckozak" type="fix" due-to="Henrik Brautaset Aronsen">
+        PropertiesUtil ignores non-string system properties. Fixes a NoClassDefFoundError initializing StatusLogger
+        caused by an NPE while initializing the static PropertiesUtil field.
+      </action>
     </release>
     <release version="2.11.0" date="2018-xx-xx" description="GA Release 2.11.0">
       <action issue="LOG4J2-2104" dev="rgoers" type="fix">


[2/2] logging-log4j2 git commit: [LOG4J2-2355] Avoid NullPointerException in PropertiesUtil.reload()

Posted by ck...@apache.org.
[LOG4J2-2355] Avoid NullPointerException in PropertiesUtil.reload()

SystemPropertiesPropertySource.forEach(..) uses Property.getProperty(..)
to resolve values.  If that value is a non-String, the value will be
null.  Since `literal` is a ConcurrentHashMap, a put(..) with null value
will yield a NullPointerException.

This is especially hard to debug in the case of e.g. StatusLogger,
which initializes PropertiesUtil as a static variable.  The class is
unable to load, throws a NoClassDefFoundError, and hides the
NullPointerException.

Here's what I got when I had a Property value that was a File:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil
	at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:78)
	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:60)


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

Branch: refs/heads/master
Commit: b0e5a134487c5b8778d3706754654d428024de88
Parents: f8113c0
Author: Henrik Brautaset Aronsen <he...@synth.no>
Authored: Fri Jun 22 14:45:26 2018 +0200
Committer: Carter Kozak <ck...@apache.org>
Committed: Fri Jun 22 11:09:04 2018 -0400

----------------------------------------------------------------------
 .../apache/logging/log4j/util/PropertiesUtil.java | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/b0e5a134/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index f5e1ecb..f1c8f15 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -330,13 +330,17 @@ public final class PropertiesUtil {
                 source.forEach(new BiConsumer<String, String>() {
                     @Override
                     public void accept(final String key, final String value) {
-                        literal.put(key, value);
-                        final List<CharSequence> tokens = PropertySource.Util.tokenize(key);
-                        if (tokens.isEmpty()) {
-                            normalized.put(source.getNormalForm(Collections.singleton(key)), value);
-                        } else {
-                            normalized.put(source.getNormalForm(tokens), value);
-                            tokenized.put(tokens, value);
+                        if (value != null) {
+                            literal.put(key, value);
+                            final List<CharSequence> tokens = PropertySource.Util.tokenize(key);
+                            if (tokens.isEmpty()) {
+                                normalized.put(source.getNormalForm(Collections.singleton(key)), value);
+                            } else {
+                                normalized.put(source.getNormalForm(tokens), value);
+                                tokenized.put(tokens, value);
+                            }
+                        } else  {
+                            LowLevelLogUtil.log("Property " + key + " was skipped because of null value.");
                         }
                     }
                 });