You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by rz...@apache.org on 2026/10/06 18:44:30 UTC

(opennlp) branch main updated: GH-1398: Add requireNonEmpty and requireNonNegative to ParamChecks (#1413)

This is an automated email from the ASF dual-hosted git repository.

rzo1 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git


The following commit(s) were added to refs/heads/main by this push:
     new c98b76298 GH-1398: Add requireNonEmpty and requireNonNegative to ParamChecks (#1413)
c98b76298 is described below

commit c98b7629840a6e08af4901eec6be3eceec02e99a
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Tue Oct 6 20:44:23 2026 +0200

    GH-1398: Add requireNonEmpty and requireNonNegative to ParamChecks (#1413)
    
    * GH-1398: Add requireNonEmpty and requireNonNegative to ParamChecks
    
    Adds requireNonEmpty (CharSequence, Collection), requireNonBlank and
    requireNonNegative (int, long) to ParamChecks and switches the inline
    checks whose condition and message already match, keeping behavior.
    
    * Use StringUtil.isUnicodeBlank in ParamChecks.requireNonBlank
---
 .../java/opennlp/tools/termvector/TermVector.java  |   4 +-
 .../java/opennlp/tools/tokenize/SubwordPiece.java  |   8 +-
 .../opennlp/tools/tokenize/WordpieceEncoder.java   |   4 +-
 .../main/java/opennlp/tools/util/ParamChecks.java  |  97 +++++++++++++++++++
 .../java/opennlp/tools/util/ext/ProviderSpec.java  |   4 +-
 .../java/opennlp/tools/util/ext/Providers.java     |   4 +-
 .../java/opennlp/tools/util/ParamChecksTest.java   | 103 ++++++++++++++++++++-
 .../dl/vectors/OnnxTextEmbedderProvider.java       |   4 +-
 .../tools/ml/maxent/BasicContextGenerator.java     |   4 +-
 .../tools/stemmer/hunspell/HunspellDictionary.java |   8 +-
 .../java/opennlp/tools/util/ResourceInstaller.java |   4 +-
 .../spellcheck/dictionary/SymSpellModel.java       |  13 +--
 .../dictionary/SymSpellModelResolver.java          |   8 +-
 13 files changed, 213 insertions(+), 52 deletions(-)

diff --git a/opennlp-api/src/main/java/opennlp/tools/termvector/TermVector.java b/opennlp-api/src/main/java/opennlp/tools/termvector/TermVector.java
index 5200224fa..bd019e9a0 100644
--- a/opennlp-api/src/main/java/opennlp/tools/termvector/TermVector.java
+++ b/opennlp-api/src/main/java/opennlp/tools/termvector/TermVector.java
@@ -92,9 +92,7 @@ public record TermVector(String term, int frequency, List<Span> spans) {
    *         {@code spans} is {@code null} or empty.
    */
   public static TermVector withSpans(String term, List<Span> spans) {
-    if (spans == null || spans.isEmpty()) {
-      throw new IllegalArgumentException("spans must not be null or empty");
-    }
+    ParamChecks.requireNonEmpty(spans, "spans");
     return new TermVector(term, spans.size(), spans);
   }
 
diff --git a/opennlp-api/src/main/java/opennlp/tools/tokenize/SubwordPiece.java b/opennlp-api/src/main/java/opennlp/tools/tokenize/SubwordPiece.java
index 2da1ea30f..8f400efcc 100644
--- a/opennlp-api/src/main/java/opennlp/tools/tokenize/SubwordPiece.java
+++ b/opennlp-api/src/main/java/opennlp/tools/tokenize/SubwordPiece.java
@@ -59,12 +59,8 @@ public record SubwordPiece(String piece, int id, int start, int end) {
     if (piece.isEmpty()) {
       throw new IllegalArgumentException("piece must not be empty");
     }
-    if (id < 0) {
-      throw new IllegalArgumentException("id must not be negative");
-    }
-    if (start < 0) {
-      throw new IllegalArgumentException("start must not be negative");
-    }
+    ParamChecks.requireNonNegative(id, "id");
+    ParamChecks.requireNonNegative(start, "start");
     if (end < start) {
       throw new IllegalArgumentException("end must be at least start");
     }
diff --git a/opennlp-api/src/main/java/opennlp/tools/tokenize/WordpieceEncoder.java b/opennlp-api/src/main/java/opennlp/tools/tokenize/WordpieceEncoder.java
index 3c47a013e..6d866ef15 100644
--- a/opennlp-api/src/main/java/opennlp/tools/tokenize/WordpieceEncoder.java
+++ b/opennlp-api/src/main/java/opennlp/tools/tokenize/WordpieceEncoder.java
@@ -239,9 +239,7 @@ public final class WordpieceEncoder implements SubwordTokenizer {
     if (unknownToken.isEmpty()) {
       throw new IllegalArgumentException("unknownToken must not be empty");
     }
-    if (maxWordCodePoints < 0) {
-      throw new IllegalArgumentException("maxWordCodePoints must not be negative");
-    }
+    ParamChecks.requireNonNegative(maxWordCodePoints, "maxWordCodePoints");
     final Map<String, Integer> byPiece = HashMap.newHashMap(vocabularyIds.size());
     for (final Map.Entry<String, Integer> entry : vocabularyIds.entrySet()) {
       if (entry.getKey() == null || entry.getValue() == null) {
diff --git a/opennlp-api/src/main/java/opennlp/tools/util/ParamChecks.java b/opennlp-api/src/main/java/opennlp/tools/util/ParamChecks.java
index dbe057aed..2ce07aee8 100644
--- a/opennlp-api/src/main/java/opennlp/tools/util/ParamChecks.java
+++ b/opennlp-api/src/main/java/opennlp/tools/util/ParamChecks.java
@@ -17,6 +17,8 @@
 
 package opennlp.tools.util;
 
+import java.util.Collection;
+
 import opennlp.tools.commons.Internal;
 
 /**
@@ -32,6 +34,9 @@ import opennlp.tools.commons.Internal;
 public final class ParamChecks {
 
   private static final String NOT_NULL_SUFFIX = " must not be null";
+  private static final String NOT_EMPTY_SUFFIX = " must not be null or empty";
+  private static final String NOT_BLANK_SUFFIX = " must not be null or blank";
+  private static final String NOT_NEGATIVE_SUFFIX = " must not be negative";
 
   private ParamChecks() {
     // utility class
@@ -54,4 +59,96 @@ public final class ParamChecks {
     }
     return value;
   }
+
+  /**
+   * Returns {@code value} if it is neither {@code null} nor empty.
+   * <p>
+   * The message of a thrown exception is {@code "<name> must not be null or empty"}.
+   *
+   * @param value The argument to check.
+   * @param name The parameter name used in the exception message.
+   * @param <T> The argument type.
+   * @return {@code value}, never {@code null} or empty.
+   * @throws IllegalArgumentException Thrown if {@code value} is {@code null} or has a length
+   *     of zero.
+   */
+  public static <T extends CharSequence> T requireNonEmpty(T value, String name) {
+    if (value == null || value.isEmpty()) {
+      throw new IllegalArgumentException(name + NOT_EMPTY_SUFFIX);
+    }
+    return value;
+  }
+
+  /**
+   * Returns {@code value} if it is neither {@code null} nor empty.
+   * <p>
+   * The message of a thrown exception is {@code "<name> must not be null or empty"}.
+   *
+   * @param value The argument to check.
+   * @param name The parameter name used in the exception message.
+   * @param <T> The argument type.
+   * @return {@code value}, never {@code null} or empty.
+   * @throws IllegalArgumentException Thrown if {@code value} is {@code null} or contains no
+   *     elements.
+   */
+  public static <T extends Collection<?>> T requireNonEmpty(T value, String name) {
+    if (value == null || value.isEmpty()) {
+      throw new IllegalArgumentException(name + NOT_EMPTY_SUFFIX);
+    }
+    return value;
+  }
+
+  /**
+   * Returns {@code value} if it is neither {@code null} nor blank.
+   * <p>
+   * A string is blank if it is empty or contains only Unicode {@code White_Space} code points,
+   * as defined by {@link StringUtil#isUnicodeBlank(CharSequence)}. The message of a thrown
+   * exception is
+   * {@code "<name> must not be null or blank"}.
+   *
+   * @param value The argument to check.
+   * @param name The parameter name used in the exception message.
+   * @return {@code value}, never {@code null} or blank.
+   * @throws IllegalArgumentException Thrown if {@code value} is {@code null} or blank.
+   */
+  public static String requireNonBlank(String value, String name) {
+    if (StringUtil.isUnicodeBlank(value)) {
+      throw new IllegalArgumentException(name + NOT_BLANK_SUFFIX);
+    }
+    return value;
+  }
+
+  /**
+   * Returns {@code value} if it is not negative.
+   * <p>
+   * The message of a thrown exception is {@code "<name> must not be negative"}.
+   *
+   * @param value The argument to check.
+   * @param name The parameter name used in the exception message.
+   * @return {@code value}, never negative.
+   * @throws IllegalArgumentException Thrown if {@code value} is less than zero.
+   */
+  public static int requireNonNegative(int value, String name) {
+    if (value < 0) {
+      throw new IllegalArgumentException(name + NOT_NEGATIVE_SUFFIX);
+    }
+    return value;
+  }
+
+  /**
+   * Returns {@code value} if it is not negative.
+   * <p>
+   * The message of a thrown exception is {@code "<name> must not be negative"}.
+   *
+   * @param value The argument to check.
+   * @param name The parameter name used in the exception message.
+   * @return {@code value}, never negative.
+   * @throws IllegalArgumentException Thrown if {@code value} is less than zero.
+   */
+  public static long requireNonNegative(long value, String name) {
+    if (value < 0) {
+      throw new IllegalArgumentException(name + NOT_NEGATIVE_SUFFIX);
+    }
+    return value;
+  }
 }
diff --git a/opennlp-api/src/main/java/opennlp/tools/util/ext/ProviderSpec.java b/opennlp-api/src/main/java/opennlp/tools/util/ext/ProviderSpec.java
index bbcb8433d..e98c4cee3 100644
--- a/opennlp-api/src/main/java/opennlp/tools/util/ext/ProviderSpec.java
+++ b/opennlp-api/src/main/java/opennlp/tools/util/ext/ProviderSpec.java
@@ -258,9 +258,7 @@ public final class ProviderSpec {
    * @throws IllegalArgumentException Thrown if {@code suffix} is {@code null} or empty.
    */
   public boolean locationEndsWith(final String suffix) {
-    if (suffix == null || suffix.isEmpty()) {
-      throw new IllegalArgumentException("suffix must not be null or empty");
-    }
+    ParamChecks.requireNonEmpty(suffix, "suffix");
     if (location == null) {
       return false;
     }
diff --git a/opennlp-api/src/main/java/opennlp/tools/util/ext/Providers.java b/opennlp-api/src/main/java/opennlp/tools/util/ext/Providers.java
index 6de6d511f..b318be0e7 100644
--- a/opennlp-api/src/main/java/opennlp/tools/util/ext/Providers.java
+++ b/opennlp-api/src/main/java/opennlp/tools/util/ext/Providers.java
@@ -378,9 +378,7 @@ public final class Providers<P extends Provider<?>> {
    *                                    priority.
    */
   public Optional<P> byName(final String name) {
-    if (name == null || name.isBlank()) {
-      throw new IllegalArgumentException("name must not be null or blank");
-    }
+    ParamChecks.requireNonBlank(name, "name");
     if (disabledNames().contains(name)) {
       return Optional.empty();
     }
diff --git a/opennlp-api/src/test/java/opennlp/tools/util/ParamChecksTest.java b/opennlp-api/src/test/java/opennlp/tools/util/ParamChecksTest.java
index 33f497aa2..f6e94a2d6 100644
--- a/opennlp-api/src/test/java/opennlp/tools/util/ParamChecksTest.java
+++ b/opennlp-api/src/test/java/opennlp/tools/util/ParamChecksTest.java
@@ -17,6 +17,10 @@
 
 package opennlp.tools.util;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
@@ -26,9 +30,9 @@ import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /**
- * Pins the contract of {@link ParamChecks#requireNonNullArg(Object, String)}: a non-null
- * argument is returned as is, and a {@code null} argument is rejected with an
- * {@link IllegalArgumentException} whose message names the parameter.
+ * Pins the contract of the {@link ParamChecks} helpers: a valid argument is returned as is,
+ * and an invalid argument is rejected with an {@link IllegalArgumentException} whose message
+ * names the parameter.
  */
 public class ParamChecksTest {
 
@@ -57,4 +61,97 @@ public class ParamChecksTest {
         () -> ParamChecks.requireNonNullArg(null, name));
     assertEquals(name + " must not be null", e.getMessage());
   }
+
+  @ParameterizedTest
+  @ValueSource(strings = {" ", "text", "😀"})
+  void testNonEmptyCharSequenceIsReturnedUnchanged(String value) {
+    assertSame(value, ParamChecks.requireNonEmpty(value, "text"));
+    final StringBuilder builder = new StringBuilder(value);
+    assertSame(builder, ParamChecks.requireNonEmpty(builder, "text"));
+  }
+
+  @Test
+  void testNullCharSequenceIsRejectedAsEmpty() {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonEmpty((String) null, "suffix"));
+    assertEquals("suffix must not be null or empty", e.getMessage());
+  }
+
+  @Test
+  void testEmptyCharSequenceIsRejected() {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonEmpty(new StringBuilder(), "sep"));
+    assertEquals("sep must not be null or empty", e.getMessage());
+  }
+
+  @Test
+  void testNonEmptyCollectionIsReturnedUnchanged() {
+    final List<String> list = List.of("a");
+    assertSame(list, ParamChecks.requireNonEmpty(list, "spans"));
+    final Set<Integer> set = Set.of(1, 2);
+    assertSame(set, ParamChecks.requireNonEmpty(set, "spans"));
+  }
+
+  @Test
+  void testNullCollectionIsRejectedAsEmpty() {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonEmpty((List<String>) null, "spans"));
+    assertEquals("spans must not be null or empty", e.getMessage());
+  }
+
+  @Test
+  void testEmptyCollectionIsRejected() {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonEmpty(new ArrayList<String>(), "spans"));
+    assertEquals("spans must not be null or empty", e.getMessage());
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {"text", " a ", "😀", "\u001C"})
+  void testNonBlankStringIsReturnedUnchanged(String value) {
+    assertSame(value, ParamChecks.requireNonBlank(value, "name"));
+  }
+
+  @Test
+  void testNullStringIsRejectedAsBlank() {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonBlank(null, "name"));
+    assertEquals("name must not be null or blank", e.getMessage());
+  }
+
+  @ParameterizedTest
+  @ValueSource(strings = {"", " ", "\t", " \n\r ", "\u00A0", "\u2003", "\u3000", "\u0085"})
+  void testBlankStringIsRejected(String value) {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonBlank(value, "language"));
+    assertEquals("language must not be null or blank", e.getMessage());
+  }
+
+  @ParameterizedTest
+  @ValueSource(ints = {0, 1, Integer.MAX_VALUE})
+  void testNonNegativeIntIsReturnedUnchanged(int value) {
+    assertEquals(value, ParamChecks.requireNonNegative(value, "id"));
+  }
+
+  @ParameterizedTest
+  @ValueSource(ints = {-1, Integer.MIN_VALUE})
+  void testNegativeIntIsRejected(int value) {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonNegative(value, "id"));
+    assertEquals("id must not be negative", e.getMessage());
+  }
+
+  @ParameterizedTest
+  @ValueSource(longs = {0L, 1L, Long.MAX_VALUE})
+  void testNonNegativeLongIsReturnedUnchanged(long value) {
+    assertEquals(value, ParamChecks.requireNonNegative(value, "count"));
+  }
+
+  @ParameterizedTest
+  @ValueSource(longs = {-1L, Long.MIN_VALUE})
+  void testNegativeLongIsRejected(long value) {
+    final IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
+        () -> ParamChecks.requireNonNegative(value, "count"));
+    assertEquals("count must not be negative", e.getMessage());
+  }
 }
diff --git a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/OnnxTextEmbedderProvider.java b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/OnnxTextEmbedderProvider.java
index 0d6757cfa..a07da704e 100644
--- a/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/OnnxTextEmbedderProvider.java
+++ b/opennlp-core/opennlp-ml/opennlp-dl/src/main/java/opennlp/dl/vectors/OnnxTextEmbedderProvider.java
@@ -107,9 +107,7 @@ public final class OnnxTextEmbedderProvider implements TextEmbedderProvider {
       throw new IllegalArgumentException("model must be a regular file: " + model);
     }
     final String vocabulary = spec.option(VOCABULARY_OPTION, null);
-    if (vocabulary == null || vocabulary.isBlank()) {
-      throw new IllegalArgumentException(VOCABULARY_OPTION + " must not be null or blank");
-    }
+    ParamChecks.requireNonBlank(vocabulary, VOCABULARY_OPTION);
     final boolean lowerCase = booleanOption(spec, LOWER_CASE_OPTION);
     final boolean normalize = booleanOption(spec, NORMALIZE_OPTION);
     final Pooling pooling = poolingOption(spec);
diff --git a/opennlp-core/opennlp-ml/opennlp-ml-maxent/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java b/opennlp-core/opennlp-ml/opennlp-ml-maxent/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
index c5172f055..d45d53754 100644
--- a/opennlp-core/opennlp-ml/opennlp-ml-maxent/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
+++ b/opennlp-core/opennlp-ml/opennlp-ml-maxent/src/main/java/opennlp/tools/ml/maxent/BasicContextGenerator.java
@@ -64,9 +64,7 @@ public class BasicContextGenerator implements ContextGenerator<String> {
    *                                  backslash, or contains an unpaired surrogate.
    */
   public BasicContextGenerator(String sep) {
-    if (sep == null || sep.isEmpty()) {
-      throw new IllegalArgumentException("sep must not be null or empty");
-    }
+    ParamChecks.requireNonEmpty(sep, "sep");
     if (sep.indexOf(BACKSLASH) >= 0) {
       throw new IllegalArgumentException(
           "sep is taken as written and must not contain a backslash: " + sep);
diff --git a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/hunspell/HunspellDictionary.java b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/hunspell/HunspellDictionary.java
index a24dec907..7cc05bdb2 100644
--- a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/hunspell/HunspellDictionary.java
+++ b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/stemmer/hunspell/HunspellDictionary.java
@@ -115,12 +115,8 @@ public final class HunspellDictionary {
      *     number is not positive.
      */
     public UnsupportedDirective {
-      if (directive == null || directive.isBlank()) {
-        throw new IllegalArgumentException("directive must not be null or blank");
-      }
-      if (source == null || source.isBlank()) {
-        throw new IllegalArgumentException("source must not be null or blank");
-      }
+      ParamChecks.requireNonBlank(directive, "directive");
+      ParamChecks.requireNonBlank(source, "source");
       if (lineNumber < 1) {
         throw new IllegalArgumentException("lineNumber must be positive");
       }
diff --git a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/ResourceInstaller.java b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/ResourceInstaller.java
index aebac555f..fdbb7456e 100644
--- a/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/ResourceInstaller.java
+++ b/opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/ResourceInstaller.java
@@ -217,9 +217,7 @@ public final class ResourceInstaller {
       if (readTimeout.isZero() || readTimeout.isNegative()) {
         throw new IllegalArgumentException("readTimeout must be positive");
       }
-      if (maxRedirects < 0) {
-        throw new IllegalArgumentException("maxRedirects must not be negative");
-      }
+      ParamChecks.requireNonNegative(maxRedirects, "maxRedirects");
       if (maxDownloadBytes <= 0) {
         throw new IllegalArgumentException("maxDownloadBytes must be positive");
       }
diff --git a/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModel.java b/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModel.java
index c9a0e4bad..a832e5259 100644
--- a/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModel.java
+++ b/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModel.java
@@ -97,9 +97,9 @@ public final class SymSpellModel implements SerializableArtifact {
    */
   public SymSpellModel(String language, String name, String version, SymSpellConfig config,
                        Map<String, Long> unigrams, Map<String, Long> bigrams) {
-    this.language = requireNonBlank(language, "language");
-    this.name = requireNonBlank(name, "name");
-    this.version = requireNonBlank(version, "version");
+    this.language = ParamChecks.requireNonBlank(language, "language");
+    this.name = ParamChecks.requireNonBlank(name, "name");
+    this.version = ParamChecks.requireNonBlank(version, "version");
     this.config = ParamChecks.requireNonNullArg(config, "config");
     ParamChecks.requireNonNullArg(unigrams, "unigrams");
     ParamChecks.requireNonNullArg(bigrams, "bigrams");
@@ -166,11 +166,4 @@ public final class SymSpellModel implements SerializableArtifact {
   public Class<?> getArtifactSerializerClass() {
     return SymSpellModelSerializer.class;
   }
-
-  private static String requireNonBlank(String value, String field) {
-    if (value == null || value.isBlank()) {
-      throw new IllegalArgumentException(field + " must not be null or blank");
-    }
-    return value;
-  }
 }
diff --git a/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModelResolver.java b/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModelResolver.java
index 3b18b62b9..f10fa4b53 100644
--- a/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModelResolver.java
+++ b/opennlp-extensions/opennlp-spellcheck/src/main/java/opennlp/spellcheck/dictionary/SymSpellModelResolver.java
@@ -82,9 +82,7 @@ public final class SymSpellModelResolver {
                                String nameFragment) {
     this.finder = ParamChecks.requireNonNullArg(finder, "finder");
     this.loader = ParamChecks.requireNonNullArg(loader, "loader");
-    if (nameFragment == null || nameFragment.isBlank()) {
-      throw new IllegalArgumentException("nameFragment must not be null or blank");
-    }
+    ParamChecks.requireNonBlank(nameFragment, "nameFragment");
     this.nameFragment = nameFragment;
   }
 
@@ -115,9 +113,7 @@ public final class SymSpellModelResolver {
    */
   public Optional<SymSpellModel> resolveByLanguage(String language, boolean reloadCache)
       throws IOException {
-    if (language == null || language.isBlank()) {
-      throw new IllegalArgumentException("language must not be null or blank");
-    }
+    ParamChecks.requireNonBlank(language, "language");
 
     final Set<ClassPathModelEntry> entries = finder.findModels(reloadCache);
     for (ClassPathModelEntry entry : entries) {