[main] Add @Required and validation to StringMatchFilter text attribute (#3158 port)#4153
[main] Add @Required and validation to StringMatchFilter text attribute (#3158 port)#4153vpelikh wants to merge 5 commits into
@Required and validation to StringMatchFilter text attribute (#3158 port)#4153Conversation
340a851 to
fd62c22
Compare
@Required and validation to StringMatchFilter text attribute (#3158)@Required and validation to StringMatchFilter text attribute (#3158 port)
fd62c22 to
829c17c
Compare
|
It turns out the original author (@JWT007) already started porting this to main over in PR #3510, but that PR stalled and still has some unresolved review comments from @vy and @ppkarwasz . Since he already did half the work, could you pull his commits into this PR (to preserve his authorship), and then address the review feedback that @vy and @ppkarwasz left on #3510? If you can resolve those review comments here in this PR, I will close the old PR and we can focus on getting yours reviewed and merged! |
* Guard against NPEs * added private constructor to builder * added getText() accessor * add JVerify nullability annotations * added detailed javadoc with implementation details * optimized AbstractLifeCycle and AbstractFilter "equalsImpl" implementations * added changelog
829c17c to
8b15430
Compare
|
Thanks @ramanathan1504 — I've pulled @JWT007's original port commits from #3510 into this PR (authorship preserved) and addressed the open review feedback that @vy and @ppkarwasz left there: @ppkarwasz —
@ppkarwasz — the misspelled-plugin-name test didn't belong here
@vy / @ppkarwasz — avoid cosmetic changes on existing code
|
- Preserve @JWT007's original port commits (authorship retained). - Make setText(null) throw NullPointerException and setText("") throw IllegalArgumentException, differentiating the @nonnull and non-empty validation levels (review by ppkarwasz). - Replace the misspelled-plugin-name configuration test with a correct StringMatchFilter element lacking the required 'text' attribute, so the test exercises the filter's own @required validation rather than PluginBuilder name resolution (review by ppkarwasz). - Revert cosmetic method reordering and filter() javadoc rewrites; keep the existing method order and minimal documentation (review by vy/ppkarwasz). - Drop the out-of-scope equalsImpl/Assert cosmetic refactors into a separate follow-up change (review by vy).
8b15430 to
c0f92de
Compare
Ports the
StringMatchFiltervalidation work from the 2.x branch (#3158), originally started by @JWT007 in #3510 (his commit authorship is preserved), and resolves the earlier review feedback.Changes
StringMatchFilter.java: Thetextbuilder attribute is now marked@Required(message = "No text provided for StringMatchFilter")so a missing attribute fails configuration validation. The constructor validates withAssert.requireNonEmpty(...). The builder'ssetText(@NonNull String)throwsNullPointerExceptionfor anullargument andIllegalArgumentExceptionfor an empty string.build()returnsnull(logged error) whentextis missing, and a newgetText()accessor was added.StringMatchFilterTest.java: Added tests covering valid construction, emptytextrejection,nulltextrejection (NullPointerException), missing-attribute rejection via config, and the post-stop()guard.log4j2-stringmatchfilter-3153-ok.xmlandlog4j2-stringmatchfilter-3153-nok.xmlfixtures. Thenokconfig uses a correctly named<StringMatchFilter/>element with notextattribute (the earlier version used a misspelled plugin name and was replaced).Why
An empty or missing
textattribute onStringMatchFilterpreviously resulted in either a crypticNullPointerExceptionat runtime (afterstop()) or silently matching the empty string against every event. This change provides clear validation at configuration time and graceful degradation.Notes
AbstractFilter/AbstractLifeCycle/Assert(equalsImpl, etc.) that appeared in the original [main] Add@Requiredand validation toStringMatchFiltertextattribute (#3158 port) #4153 diff were dropped to keep this PR focused onStringMatchFiltervalidation; they can be handled in a follow-up.