languagetool-org/languagetool · error · IllegalArgumentException
minOccurrence must <= maxOccurrence: minOccurrence ${minOccu
Error message
minOccurrence must <= maxOccurrence: minOccurrence ${minOccurrence}, maxOccurrence ${maxOccurrence} What it means
Builder consistency check fired when PatternTokenBuilder.build() assembles the PatternToken: the previously set minOccurrence exceeds maxOccurrence, which is impossible for a range quantifier. It means the chain of builder calls (e.g. minOccurrence(n) followed by maxOccurrence(m) with m < n) requested an empty occurrence range.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternTokenBuilder.java:163
* given token actually is a baseform.
* @since 3.8
*/
public PatternTokenBuilder matchInflectedForms() {
matchInflectedForms = true;
return this;
}
public PatternToken build() {
PatternToken patternToken;
patternToken = new PatternToken(token, caseSensitive, regexp, matchInflectedForms);
if (posTag != null) {
patternToken.setPosToken(new PatternToken.PosToken(posTag, regexp, false));
}
if (isWhiteSpaceSet) {
patternToken.setWhitespaceBefore(isWhiteSpaceBefore);
}
if (maxOccurrence < minOccurrence) {
throw new IllegalArgumentException("minOccurrence must <= maxOccurrence: minOccurrence " + minOccurrence + ", maxOccurrence " + maxOccurrence);
}
if (tokenException != null) {
patternToken.setStringPosException(tokenException, true, false, false, false, false, null, false, false, false);
}
patternToken.setMinOccurrence(minOccurrence);
patternToken.setMaxOccurrence(maxOccurrence);
patternToken.setNegation(negation);
patternToken.setSkipNext(skip);
patternToken.setInsideMarker(marker);
return patternToken;
}
}
View on GitHub (pinned to 2e990059ce)
Solutions
- Set maxOccurrence to a value greater than or equal to minOccurrence before calling build()
- Review the order of minOccurrence()/maxOccurrence() calls in the builder chain to make sure the last call does not shrink the range below the minimum
- If the token is meant to be optional, use minOccurrence(0) with a suitable maxOccurrence instead of lowering maxOccurrence
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternTokenBuilder.java:163 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/f35dd983cba4422f.
Report an issue: GitHub.