languagetool-org/languagetool · error · NullPointerException
disambiguated POS cannot be null with posSelect == null and
Error message
disambiguated POS cannot be null with posSelect == null and " + disambAction
What it means
Constructor invariant check for DisambiguationPatternRule: an action that needs a replacement POS (e.g. REPLACE) was requested, but both disambiguatedPOS and posSelect are null, so there is no POS to apply. This is an API misuse guard — rule XML is normally validated earlier, so it fires mostly when building rules programmatically.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/rules/DisambiguationPatternRule.java:76
* @param description Description to be shown (name)
* @param disambAction the action to be executed on found token(s)
* @since public since 2.5
*/
public DisambiguationPatternRule(String id, String description,
Language language, List<PatternToken> patternTokens,
String disambiguatedPOS, Match posSelect,
DisambiguatorAction disambAction) {
super(id, description, language, patternTokens, true);
if (disambiguatedPOS == null && posSelect == null
&& disambAction != DisambiguatorAction.UNIFY
&& disambAction != DisambiguatorAction.ADD
&& disambAction != DisambiguatorAction.REMOVE
&& disambAction != DisambiguatorAction.IMMUNIZE
&& disambAction != DisambiguatorAction.REPLACE
&& disambAction != DisambiguatorAction.FILTERALL
&& disambAction != DisambiguatorAction.IGNORE_SPELLING
&& disambAction != DisambiguatorAction.ADDCHUNK) {
throw new NullPointerException("disambiguated POS cannot be null with posSelect == null and " + disambAction);
}
this.disambiguatedPOS = disambiguatedPOS;
this.matchElement = posSelect;
this.disAction = Objects.requireNonNull(disambAction);
setMessage("");
suggestionsOutMsg = "";
}
/**
* Used to add new interpretations.
* @param newReadings
* An array of AnalyzedTokens. The length of the array should be the
* same as the number of the tokens matched and selected by
* {@code <marker>...</marker>} elements.
*/
public final void setNewInterpretations(AnalyzedToken[] newReadings) {
newTokenReadings = newReadings.clone();
}View on GitHub (pinned to 2e990059ce)
Solutions
- Provide a non-null disambiguatedPOS or a posSelect Match when using a POS-modifying action
- Use the correct DisambiguatorAction (e.g. UNIFY or IGNORE) when no POS replacement is intended
- Fix the rule XML so the action element carries its postag or match attribute
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/tagging/disambiguation/rules/DisambiguationPatternRule.java:76 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/cf2ac0c74adfb3bc.
Report an issue: GitHub.