Skip to content

[main] Fix RegexFilter NPE when useRawMsg is null (#3265 port)#4152

Open
vpelikh wants to merge 2 commits into
apache:mainfrom
vpelikh:GH-3265-port-to-main
Open

[main] Fix RegexFilter NPE when useRawMsg is null (#3265 port)#4152
vpelikh wants to merge 2 commits into
apache:mainfrom
vpelikh:GH-3265-port-to-main

Conversation

@vpelikh

@vpelikh vpelikh commented Jun 26, 2026

Copy link
Copy Markdown

Ports the fix from #3265 from the 2.x branch to main.

In the RegexFilter.createFilter() factory method, the useRawMsg parameter is declared as Boolean (boxed). When passed directly to the RegexFilter(boolean raw, ...) constructor, a null value causes an NPE during unboxing.

This change uses Boolean.TRUE.equals(useRawMsg) instead, which safely handles null by defaulting to false.

Changes

  • log4j-core/.../filter/RegexFilter.java: Changed useRawMsgBoolean.TRUE.equals(useRawMsg) in constructor call
  • log4j-core-test/.../filter/RegexFilterTest.java: Added test ensuring no exception when useRawMsg is null

@vpelikh
vpelikh force-pushed the GH-3265-port-to-main branch from f0af2d0 to 666c239 Compare June 26, 2026 07:25
@vpelikh vpelikh changed the title [main] Fix RegexFilter NPE when useRawMsg is null (#3265) [main] Fix RegexFilter NPE when useRawMsg is null (#3265 port) Jun 26, 2026
@vpelikh vpelikh mentioned this pull request Jun 26, 2026
27 tasks
@ramanathan1504

Copy link
Copy Markdown
Contributor

@vpelikh, Looks good, the fix and tests work perfectly locally and adapt well to the Log4j 3 variables.

However, we don't port changelog entries for direct syncs from 2.x to main. Please delete the changelog file (src/changelog/.3.x.x/3239_npe_fix_regex_filter_creator.xml). I'll merge this as soon as it's removed!

Avoid NPE when unboxing a null Boolean by using Boolean.TRUE.equals().

Signed-off-by: Vasily Pelikh <2010720+vpelikh@users.noreply.github.com>
@vpelikh
vpelikh force-pushed the GH-3265-port-to-main branch from 666c239 to de16d43 Compare July 16, 2026 07:19
@vpelikh

vpelikh commented Jul 16, 2026

Copy link
Copy Markdown
Author

Thank you for the review, @ramanathan1504!

I've removed the changelog file from this PR. I also just went through all my other open backport PRs a few minutes ago and cleaned up the changelog entries there, so they should all be consistent now and won't cause any extra noise.

@ramanathan1504

Copy link
Copy Markdown
Contributor

Thanks for the update, @vpelikh!

One quick request for the future: please try to avoid force-pushing when updating a PR. While it's fine for this because here there in no PR review comments, force-pushing erases the commit history and makes it very difficult for us to review iterative changes.

Everything else looks perfect. Thanks

@ramanathan1504

Copy link
Copy Markdown
Contributor

@vpelikh
For future PRs, please make sure to check our Development Guidelines (BUILDING.adoc) and run ./mvnw verify (or at least ./mvnw spotless:apply) locally before committing. This will help catch these formatting errors before the CI does!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants