You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2025/01/08 09:10:53 UTC
(logging-log4j2) branch 2.x updated: Fix NPE in RegexFilter creator. (#3265)
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/2.x by this push:
new 95b586dce9 Fix NPE in RegexFilter creator. (#3265)
95b586dce9 is described below
commit 95b586dce9f26f3152fc32fd641b94e76634367c
Author: Jay Katariya <32...@users.noreply.github.com>
AuthorDate: Wed Jan 8 01:10:47 2025 -0800
Fix NPE in RegexFilter creator. (#3265)
Closes #3239
---
.../org/apache/logging/log4j/core/filter/RegexFilterTest.java | 8 ++++++++
.../org/apache/logging/log4j/core/filter/RegexFilter.java | 3 ++-
src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml | 11 +++++++++++
3 files changed, 21 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 a71e3dad18..671d998258 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;
@@ -39,6 +40,13 @@ class RegexFilterTest {
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 ee5997dc10..62d41b31f5 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 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)), 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 0000000000..1f05baff67
--- /dev/null
+++ b/src/changelog/2.24.3/3239_npe_fix_regex_filter_creator.xml
@@ -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>