[main] Fix RegexFilter NPE when useRawMsg is null (#3265 port)#4152
[main] Fix RegexFilter NPE when useRawMsg is null (#3265 port)#4152vpelikh wants to merge 2 commits into
useRawMsg is null (#3265 port)#4152Conversation
f0af2d0 to
666c239
Compare
useRawMsg is null (#3265)useRawMsg is null (#3265 port)
|
@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>
666c239 to
de16d43
Compare
|
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. |
|
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 |
|
@vpelikh |
Ports the fix from #3265 from the
2.xbranch tomain.In the
RegexFilter.createFilter()factory method, theuseRawMsgparameter is declared asBoolean(boxed). When passed directly to theRegexFilter(boolean raw, ...)constructor, anullvalue causes an NPE during unboxing.This change uses
Boolean.TRUE.equals(useRawMsg)instead, which safely handlesnullby defaulting tofalse.Changes
log4j-core/.../filter/RegexFilter.java: ChangeduseRawMsg→Boolean.TRUE.equals(useRawMsg)in constructor calllog4j-core-test/.../filter/RegexFilterTest.java: Added test ensuring no exception whenuseRawMsgisnull