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

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


The following commit(s) were added to refs/heads/master by this push:
     new 1392351  [LOG4J2-3095] Category.setLevel should accept null value.
1392351 is described below

commit 1392351df642658f72edea230c15be84e16018eb
Author: Gary Gregory <[email protected]>
AuthorDate: Sat May 29 17:19:52 2021 -0400

    [LOG4J2-3095] Category.setLevel should accept null value.
---
 log4j-1.2-api/src/main/java/org/apache/log4j/Category.java    |  8 ++++++--
 .../src/test/java/org/apache/log4j/CategoryTest.java          | 11 +++++++++++
 src/changes/changes.xml                                       |  3 +++
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java 
b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
index b0a0912..755cd73 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/Category.java
@@ -221,8 +221,12 @@ public class Category {
         return getEffectiveLevel();
     }
 
+    private String getLevelStr(final Priority priority) {
+        return priority == null ? null : priority.levelStr;
+    }
+
     public void setLevel(final Level level) {
-        setLevel(level.levelStr);
+        setLevel(getLevelStr(level));
     }
 
     public final Level getPriority() {
@@ -230,7 +234,7 @@ public class Category {
     }
 
     public void setPriority(final Priority priority) {
-        setLevel(priority.levelStr);
+        setLevel(getLevelStr(priority));
     }
 
     private void setLevel(final String levelStr) {
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java 
b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
index e7bd5ad..1adbafc 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/CategoryTest.java
@@ -165,6 +165,17 @@ public class CategoryTest {
         logger.setPriority(debug);
     }
 
+    /**
+     * Tests setPriority(Priority).
+     *
+     * @deprecated
+     */
+    @Deprecated
+    @Test
+    public void testSetPriorityNull() {
+        Logger.getLogger("org.example.foo").setPriority(null);
+    }
+    
     @Test
     public void testClassName() {
         final Category category = Category.getInstance("TestCategory");
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 98f5010..d5bf690 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -248,6 +248,9 @@
         - org.springframework:spring-webmvc ..................... 5.3.3 -> 
5.3.5
         - org.tukaani:xz ............................................ 1.8 -> 
1.9
       </action>
+      <action issue="LOG4J2-3095" dev="ggregory" type="fix" due-to="Kenny 
MacLeod, Gary Gregory">
+        Category.setLevel should accept null value.
+      </action>
     </release>
     <release version="2.14.1" date="2021-03-06" description="GA Release 
2.14.1">
       <!-- FIXES -->

Reply via email to