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 a71e3dad18d..671d998258b 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 @@ 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; @@ -39,6 +40,13 @@ static void before() { StatusLogger.getLogger().setLevel(Level.OFF); } + @Test + void testRegexFilterDoesNotThrowWithAllTheParametersExceptRegexEqualNull() { + assertDoesNotThrow(() -> { + RegexFilter.createFilter(".* test .*", null, null, null, null); + }); + } + @Test void testThresholds() throws Exception { RegexFilter filter = RegexFilter.createFilter(".* test .*", null, false, 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 ee5997dc10f..62d41b31f59 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 @@ -148,7 +148,8 @@ public static RegexFilter createFilter( LOGGER.error("A regular expression must be provided for RegexFilter"); return null; } - return new RegexFilter(useRawMsg, Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch); + return new RegexFilter( + Boolean.TRUE.equals(useRawMsg), Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch); } private static int toPatternFlags(final String[] patternFlags) diff --git a/src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml b/src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml new file mode 100644 index 00000000000..1f05baff679 --- /dev/null +++ b/src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml @@ -0,0 +1,11 @@ + + + + + Fix for RegexCreator NPE, the constructor expects a boolean primitive, + but the createFilter static method was boxed. Fixed that to remove the NPE issues. + +