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 a3e8bf3d025..9a1915f662b 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; @@ -110,4 +111,11 @@ public void testParameterizedMsg() throws Exception { 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 400bd42e01e..60890f0ff8f 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 static RegexFilter createFilter( 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)