JWT007 opened a new issue, #3153:
URL: https://github.com/apache/logging-log4j2/issues/3153
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;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]