@@ -57,8 +57,15 @@ public final class StringMatchFilter extends AbstractFilter {
57
57
* @throws IllegalArgumentException if the {@code text} argument is {@code null} or blank
58
58
*/
59
59
private StringMatchFilter (final Builder builder ) {
60
+
60
61
super (builder );
61
- this .text = Assert .requireNonEmpty (builder .text , "The 'text' argument must not be null." );
62
+
63
+ if (Strings .isNotEmpty (builder .text )) {
64
+ this .text = builder .text ;
65
+ } else {
66
+ throw new IllegalArgumentException ("The 'text' argument must not be null or empty." );
67
+ }
68
+
62
69
}
63
70
64
71
/**
@@ -72,7 +79,7 @@ public String getText() {
72
79
/**
73
80
* {@inheritDoc}
74
81
* <p>
75
- * This implementation performs the filter evaluation on the given event's formatted messsage .
82
+ * This implementation performs the filter evaluation on the given event's formatted message .
76
83
* </p>
77
84
*
78
85
* @throws NullPointerException if the given {@code event} is {@code null}
@@ -549,23 +556,24 @@ public Builder setText(final String text) {
549
556
return this ;
550
557
}
551
558
552
- boolean isValid () {
553
- return Strings .isNotEmpty (this .text );
554
- }
555
-
556
559
/** {@inheritDoc} */
557
560
@ Override
558
561
public @ Nullable StringMatchFilter build () {
559
562
560
- if (!isValid ()) {
563
+ // validate the 'text' attribute
564
+ if (this .text == null ) {
565
+ LOGGER .error ("Unable to create StringMatchFilter: The 'text' attribute must be configured." );
561
566
return null ;
562
567
}
563
568
564
- if (this .text == null ) {
565
- throw new IllegalStateException ("The 'text' attribute has not been set." );
569
+ // build with *safety* to not throw unexpected exceptions
570
+ try {
571
+ return new StringMatchFilter (this );
572
+ } catch (final Exception ex ) {
573
+ LOGGER .error ("Unable to create StringMatchFilter: {}" , ex .getMessage (), ex );
574
+ return null ;
566
575
}
567
576
568
- return new StringMatchFilter (this );
569
577
}
570
578
}
571
579
}
0 commit comments