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
- Clamp or correct minMatch to be >= 0 before constructing the RepeatPatternExpr.
- Verify the caller passing minMatch is not passing an error sentinel (-1) or an uninitialized value.
- If the pattern is truly optional, use minMatch 0 instead of a negative value.
- 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
- Never use negative sentinels for minMatch; use 0 for optional and maxMatch=-1 for unbounded.
- Validate repeat bounds at the config/CLI boundary before building patterns.
- Write unit tests for bound-validation of every custom pattern builder.
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
- Invalid nextBranchIndex=
- Invalid captureGroupId=
- Cannot put a child trie with no keys
- Value cannot be null
- Unsupported subScoreType
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 lowView on GitHub (pinned to 1b7edd19c4)