@@ -57,8 +57,15 @@ public final class StringMatchFilter extends AbstractFilter {
5757 * @throws IllegalArgumentException if the {@code text} argument is {@code null} or blank
5858 */
5959 private StringMatchFilter (final Builder builder ) {
60+
6061 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+
6269 }
6370
6471 /**
@@ -72,7 +79,7 @@ public String getText() {
7279 /**
7380 * {@inheritDoc}
7481 * <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 .
7683 * </p>
7784 *
7885 * @throws NullPointerException if the given {@code event} is {@code null}
@@ -549,23 +556,24 @@ public Builder setText(final String text) {
549556 return this ;
550557 }
551558
552- boolean isValid () {
553- return Strings .isNotEmpty (this .text );
554- }
555-
556559 /** {@inheritDoc} */
557560 @ Override
558561 public @ Nullable StringMatchFilter build () {
559562
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." );
561566 return null ;
562567 }
563568
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 ;
566575 }
567576
568- return new StringMatchFilter (this );
569577 }
570578 }
571579}
0 commit comments