-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
bugIncorrect, unexpected, or unintended behavior of existing codeIncorrect, unexpected, or unintended behavior of existing codeconfigurationAffects the configuration system in a general wayAffects the configuration system in a general waygood first issueIssues that are good for contributors looking to get startedIssues that are good for contributors looking to get startedjavaPull requests that update Java codePull requests that update Java codewaiting-for-maintainer
Description
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:
@PluginBuilderAttribute
private String text = "";
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:
private Result filter(final String msg) {
return msg.contains(this.text) ? onMatch : onMismatch;
}
Since String#contains(s) assumes s
is NotNull.
public boolean contains(CharSequence s) {
return indexOf(s.toString()) >= 0; // <== NPE!
}
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:
/**
* Sets the logging level to use.
* @param text the logging level to use
* @return this
*/
public StringMatchFilter.Builder setMatchString(final String text) {
this.text = text;
return this;
}
ppkarwasz
Metadata
Metadata
Assignees
Labels
bugIncorrect, unexpected, or unintended behavior of existing codeIncorrect, unexpected, or unintended behavior of existing codeconfigurationAffects the configuration system in a general wayAffects the configuration system in a general waygood first issueIssues that are good for contributors looking to get startedIssues that are good for contributors looking to get startedjavaPull requests that update Java codePull requests that update Java codewaiting-for-maintainer