Closed
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;
}