stanfordnlp/CoreNLP · error · IllegalArgumentException

Invalid minMatch=

Error message

Invalid minMatch=

What it means

SequencePattern.RepeatPatternExpr's 3-arg constructor delegates to the greedy 4-arg constructor, which throws IllegalArgumentException when minMatch is negative. A repeat expression cannot require a negative number of matches, so the library rejects it at pattern-build time. Note the same message is also thrown when minMatch exceeds a non-negative maxMatch.

Solutions

  1. Clamp or correct minMatch to be >= 0 before constructing the RepeatPatternExpr.
  2. Verify the caller passing minMatch is not passing an error sentinel (-1) or an uninitialized value.
  3. If the pattern is truly optional, use minMatch 0 instead of a negative value.
  4. Check that minMatch <= maxMatch whenever maxMatch is a non-negative bound.

Example fix

// before
SequencePattern.RepeatPatternExpr r =
    new SequencePattern.RepeatPatternExpr(wordPattern, minReps, maxReps);
// after
if (minReps < 0 || (maxReps >= 0 && minReps > maxReps)) {
    throw new IllegalArgumentException("bad repeat bounds: " + minReps + "," + maxReps);
}
SequencePattern.RepeatPatternExpr r =
    new SequencePattern.RepeatPatternExpr(wordPattern, Math.max(0, minReps), maxReps);
Defensive patterns

Strategy: validation

Validate before calling

if (minMatch < 0 || (maxMatch >= 0 && minMatch > maxMatch)) {
    throw new IllegalArgumentException("repeat bounds out of range: min=" + minMatch + " max=" + maxMatch);
}

Type guard

static boolean isValidRepeatBounds(int minMatch, int maxMatch) {
    return minMatch >= 0 && (maxMatch < 0 || minMatch <= maxMatch);
}

Try / catch

try {
    RepeatPatternExpr r = new RepeatPatternExpr(pattern, minMatch, maxMatch);
} catch (IllegalArgumentException e) {
    // log and fall back to a default pattern
}

Prevention

When it happens

Trigger: Calling new SequencePattern.RepeatPatternExpr(pattern, minMatch, maxMatch) with minMatch < 0, or with minMatch > maxMatch when maxMatch >= 0.

Common situations: Computing repetition bounds from user input or regex-translation code where a '?'/'{0,n}' style quantifier is mis-encoded as a negative minimum; off-by-one sign errors when converting (min,max) range specifications.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/175fd352bfe90026. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/ling/tokensregex/SequencePattern.java:743

  }

  /**  Expression that represents a pattern that repeats for a number of times. */
  public static class RepeatPatternExpr extends PatternExpr {

    private static final long serialVersionUID = 3935482630250147745L;

    private final PatternExpr pattern;
    private final int minMatch;
    private final int maxMatch;
    private final boolean greedyMatch;

    public RepeatPatternExpr(PatternExpr pattern, int minMatch, int maxMatch) {
      this(pattern, minMatch, maxMatch, true);
    }

    public RepeatPatternExpr(PatternExpr pattern, int minMatch, int maxMatch, boolean greedy) {
      if (minMatch < 0) {
        throw new IllegalArgumentException("Invalid minMatch=" + minMatch);
      }
      if (maxMatch >= 0 && minMatch > maxMatch) {
        throw new IllegalArgumentException("Invalid minMatch=" + minMatch + ", maxMatch=" + maxMatch);
      }
      this.pattern = pattern;
      this.minMatch = minMatch;
      this.maxMatch = maxMatch;
      this.greedyMatch = greedy;
    }

    @Override
    protected Frag build()
    {
      Frag f = pattern.build();
      if (minMatch == 1 && maxMatch == 1) {
        return f;
      } else if (minMatch <= 5 && maxMatch <= 5 && greedyMatch) {
        // Make copies if number of matches is low

View on GitHub (pinned to 1b7edd19c4)