2525import org .apache .logging .log4j .core .config .plugins .Plugin ;
2626import org .apache .logging .log4j .core .config .plugins .PluginBuilderAttribute ;
2727import org .apache .logging .log4j .core .config .plugins .PluginBuilderFactory ;
28+ import org .apache .logging .log4j .core .config .plugins .validation .constraints .Required ;
29+ import org .apache .logging .log4j .core .util .Assert ;
2830import org .apache .logging .log4j .message .Message ;
2931import org .apache .logging .log4j .util .PerformanceSensitive ;
3032
@@ -41,7 +43,7 @@ public final class StringMatchFilter extends AbstractFilter {
4143
4244 private StringMatchFilter (final String text , final Result onMatch , final Result onMismatch ) {
4345 super (onMatch , onMismatch );
44- this .text = text ;
46+ this .text = Assert . requireNonEmpty ( text , "text" ) ;
4547 }
4648
4749 @ Override
@@ -235,21 +237,26 @@ public static StringMatchFilter.Builder newBuilder() {
235237
236238 public static class Builder extends AbstractFilterBuilder <StringMatchFilter .Builder >
237239 implements org .apache .logging .log4j .core .util .Builder <StringMatchFilter > {
240+
238241 @ PluginBuilderAttribute
239- private String text = "" ;
242+ @ Required (message = "No text provided for StringMatchFilter" )
243+ private String text ;
240244
241245 /**
242246 * Sets the text to search in event messages.
243247 * @param text the text to search in event messages.
244248 * @return this instance.
245249 */
246250 public StringMatchFilter .Builder setMatchString (final String text ) {
247- this .text = text ;
251+ this .text = Assert . requireNonEmpty ( text , "The 'text' argument must not be null or empty." ) ;
248252 return this ;
249253 }
250254
251255 @ Override
252256 public StringMatchFilter build () {
257+ if (!isValid ()) {
258+ return null ;
259+ }
253260 return new StringMatchFilter (this .text , this .getOnMatch (), this .getOnMismatch ());
254261 }
255262 }
0 commit comments