Skip to content

Commit

Permalink
Fix(apache#3239) NPE, for RegexFilter creator.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaykataria1111 committed Jan 8, 2025
1 parent 8908092 commit bba4db6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="3239" link="https://github.com/apache/logging-log4j2/issues/3239"/>
<description format="asciidoc">
Fix for RegexCreator NPE, the constructor expects a boolean primitive,
but the createFilter static method was boxed. Fixed that to remove the NPE issues.
</description>
</entry>

0 comments on commit bba4db6

Please sign in to comment.