Skip to content

Commit 95b586d

Browse files
Fix NPE in RegexFilter creator. (#3265)
Closes #3239
1 parent 8908092 commit 95b586d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

log4j-core-test/src/test/java/org/apache/logging/log4j/core/filter/RegexFilterTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.hamcrest.CoreMatchers.equalTo;
2020
import static org.hamcrest.MatcherAssert.assertThat;
21+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
2122
import static org.junit.jupiter.api.Assertions.assertNull;
2223
import static org.junit.jupiter.api.Assertions.assertSame;
2324
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -39,6 +40,13 @@ static void before() {
3940
StatusLogger.getLogger().setLevel(Level.OFF);
4041
}
4142

43+
@Test
44+
void testRegexFilterDoesNotThrowWithAllTheParametersExceptRegexEqualNull() {
45+
assertDoesNotThrow(() -> {
46+
RegexFilter.createFilter(".* test .*", null, null, null, null);
47+
});
48+
}
49+
4250
@Test
4351
void testThresholds() throws Exception {
4452
RegexFilter filter = RegexFilter.createFilter(".* test .*", null, false, null, null);

log4j-core/src/main/java/org/apache/logging/log4j/core/filter/RegexFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public static RegexFilter createFilter(
148148
LOGGER.error("A regular expression must be provided for RegexFilter");
149149
return null;
150150
}
151-
return new RegexFilter(useRawMsg, Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch);
151+
return new RegexFilter(
152+
Boolean.TRUE.equals(useRawMsg), Pattern.compile(regex, toPatternFlags(patternFlags)), match, mismatch);
152153
}
153154

154155
private static int toPatternFlags(final String[] patternFlags)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns="https://logging.apache.org/xml/ns"
4+
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
5+
type="fixed">
6+
<issue id="3239" link="https://github.com/apache/logging-log4j2/issues/3239"/>
7+
<description format="asciidoc">
8+
Fix for RegexCreator NPE, the constructor expects a boolean primitive,
9+
but the createFilter static method was boxed. Fixed that to remove the NPE issues.
10+
</description>
11+
</entry>

0 commit comments

Comments
 (0)