You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2021/12/16 23:07:44 UTC

[logging-log4j2] branch release-2.x updated: [LOG4J2-3247] PropertiesConfiguration.parseAppenderFilters NPE when parsing properties file filters.

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/release-2.x by this push:
     new 8908e1d  [LOG4J2-3247] PropertiesConfiguration.parseAppenderFilters NPE when parsing properties file filters.
8908e1d is described below

commit 8908e1dcb0906f46837e10175099001d1fe75133
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Thu Dec 16 18:07:34 2021 -0500

    [LOG4J2-3247] PropertiesConfiguration.parseAppenderFilters NPE when
    parsing properties file filters.
---
 .../log4j/config/PropertiesConfiguration.java      |  2 +-
 .../log4j/config/PropertiesConfigurationTest.java  | 25 ++++++++++------
 .../org/apache/log4j/config/ZeroFilterFixture.java | 29 ++++++++++++++++++
 .../src/test/resources/LOG4J2-3247.properties      | 34 ++++++++++++++++++++++
 src/changes/changes.xml                            |  3 ++
 5 files changed, 83 insertions(+), 10 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
index 8248499..4be864d 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/PropertiesConfiguration.java
@@ -558,7 +558,7 @@ public class PropertiesConfiguration  extends Log4j1Configuration {
                 }
             }
             if (filter != null) {
-                if (head != null) {
+                if (head == null) {
                     head = filter;
                 } else {
                     next.setNext(filter);
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
index 6e7b914..1c9df9d 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/PropertiesConfigurationTest.java
@@ -16,6 +16,15 @@
  */
 package org.apache.log4j.config;
 
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.log4j.ListAppender;
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
@@ -28,15 +37,6 @@ import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.Configurator;
 import org.junit.Test;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
 /**
  * Test configuration from Properties.
  */
@@ -92,5 +92,12 @@ public class PropertiesConfigurationTest {
         Configurator.reconfigure(configuration);
         return context;
     }
+    
+    @Test
+    public void testFilter() throws Exception {
+        try (LoggerContext loggerContext = configure("target/test-classes/LOG4J2-3247.properties")) {
+            // configure() not thrown an NPE.
+        }
+    }
 
 }
\ No newline at end of file
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java
new file mode 100644
index 0000000..67ee1c4
--- /dev/null
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/ZeroFilterFixture.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.log4j.config;
+
+import org.apache.log4j.spi.Filter;
+import org.apache.log4j.spi.LoggingEvent;
+
+public class ZeroFilterFixture extends Filter {
+
+    @Override
+    public int decide(LoggingEvent event) {
+        return 0;
+    }
+
+}
diff --git a/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties b/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties
new file mode 100644
index 0000000..40c3146
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/LOG4J2-3247.properties
@@ -0,0 +1,34 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.filter.1=org.apache.log4j.config.ZeroFilterFixture
+log4j.appender.CONSOLE.Target=System.out
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
+
+log4j.appender.A1=org.apache.log4j.FileAppender
+log4j.appender.A1.File=target/temp.A1
+log4j.appender.A1.Append=false
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-5p %c{2} - %m%n
+log4j.appender.A2=org.apache.log4j.FileAppender
+log4j.appender.A2.File=target/temp.A2
+log4j.appender.A2.Append=false
+log4j.appender.A2.layout=org.apache.log4j.TTCCLayout
+log4j.appender.A2.layout.DateFormat=ISO8601
+log4j.logger.org.apache.log4j.xml=trace, A1
+log4j.rootLogger=trace, CONSOLE, A1, A2
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d1d023c..abeac4a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -37,6 +37,9 @@
         Do not declare log4j-api-java9 and log4j-core-java9 as depdendencies as it causes problems with the
         Maven enforcer plugin.
       </action>
+      <action issue="LOG4J2-3247" dev="ggregory" type="fix">
+        PropertiesConfiguration.parseAppenderFilters NPE when parsing properties file filters.
+      </action>
     </release>
     <release version="2.16.0" date="2021-12-13" description="GA Release 2.16.0">
       <action issue="LOG4J2-3208" dev="rgoers" type="fix">