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

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


The following commit(s) were added to refs/heads/main by this push:
     new 554d8f9ee9 [main] Fix RegexFilter NPE when `useRawMsg` is null (#3265 
port) (#4152)
554d8f9ee9 is described below

commit 554d8f9ee9f2c3f84f43587fab2052741b12b6aa
Author: Vasily Pelikh <[email protected]>
AuthorDate: Sun Jul 19 15:03:37 2026 +0300

    [main] Fix RegexFilter NPE when `useRawMsg` is null (#3265 port) (#4152)
    
    * Fix RegexFilter NPE when useRawMsg is null (#3265)
    
    Avoid NPE when unboxing a null Boolean by using Boolean.TRUE.equals().
    
    Signed-off-by: Vasily Pelikh <[email protected]>
    
    * Apply spotless formatting
    
    ---------
    
    Signed-off-by: Vasily Pelikh <[email protected]>
    Co-authored-by: Ramanathan <[email protected]>
---
 .../org/apache/logging/log4j/core/filter/RegexFilterTest.java     | 8 ++++++++
 .../java/org/apache/logging/log4j/core/filter/RegexFilter.java    | 6 +++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
index a3e8bf3d02..9a1915f662 100644
--- 
a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
+++ 
b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.filter;
 
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -110,4 +111,11 @@ public class RegexFilterTest {
         final Result fmtResult = fmtFilter.filter(null, null, null, msg, 
params);
         assertThat(fmtResult, equalTo(Result.ACCEPT));
     }
+
+    @Test
+    void testRegexFilterDoesNotThrowWithAllTheParametersExceptRegexEqualNull() 
{
+        assertDoesNotThrow(() -> {
+            RegexFilter.createFilter(".* test .*", null, null, null, null);
+        });
+    }
 }
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
index 400bd42e01..60890f0ff8 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java
@@ -139,7 +139,11 @@ public final class RegexFilter extends AbstractFilter {
             LOGGER.error("A regular expression must be provided for 
RegexFilter");
             return null;
         }
-        return new RegexFilter(useRawMsg, Pattern.compile(regex, 
toPatternFlags(patternFlags)), onMatch, onMismatch);
+        return new RegexFilter(
+                Boolean.TRUE.equals(useRawMsg),
+                Pattern.compile(regex, toPatternFlags(patternFlags)),
+                onMatch,
+                onMismatch);
     }
 
     private static int toPatternFlags(final String[] patternFlags)

Reply via email to