-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
StringMatchFilter would return NPE if configured programmatically with 'null' text. #3153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for catching this problem. I believe that the missing validation affects both types of configuration. When configuring through a configuration file, it does not make sense to have an empty In case of programmatic configuration there are two possible solutions:
Probably we should implement both solutions at once. Would you be willing to make a PR? |
Hi @ppkarwasz thanks for your feedback. Unfortunately I am a bit too buried in my day job to be actively contributing - but since I am pouring over the Log4j code, I am at least trying to call a few things out where I see them. :) |
@ppkarwasz - I take it back ... I was curious if I could manage the PR since I don't do Github much. I created a PR but first time so please double-check that everything is there. |
…3158) Add improved validation in StringMatchFilter for null/empty text Co-authored-by: Jeff Thomas <[email protected]>
@ppkarwasz - one more question :) how do relevant fixes find their way into 3.x? |
That is an excellent question. We try to port them immediately, but there is usually a backlog. I have written down part of the backlog in #3161. |
@ppkarwasz - OK is that something I would need to do (i.e. PR against master) or something you do internally. |
It's optional: you can create a PR and we pretty much appreciate it, but we can also push it directly to |
@ppkarwasz - seems the PR for this one was merged too. Close as done? |
This 2.x fix is implemented with #3509 in main (3.x) |
StringMatchFilter (Log4j 2.24.1)
When parsing from XML I think if the "text" attribute is missing it will be populated with an empty string due to the Builder field:
However, if for whatever reason, someone was programmatically creating this StringMatchFilter and passed null to "Builder#setMatchString", no validation is performed in the "build()" method or the constructor.
This would lead to a deferred NPE in the
StringMatchFilter#filter
method:Since String#contains(s) assumes
s
is NotNull.I thiink standard behaviour would be to log an error and return null in the 'build()' method if the 'text' field is null.
Also there seems to be a copy/paste error in the
StringMatchFilter.Builder#setMarkerText
javadoc:The text was updated successfully, but these errors were encountered: