languagetool-org/languagetool · error · IllegalArgumentException

ConfusionCheckFilter: Index out of bounds in " + match.getRu

Error message

ConfusionCheckFilter: Index out of bounds in " + match.getRule().getFullId() + ", value: " + i

What it means

ConfusionCheckFilter.acceptRuleMatch validates the gendernumberFrom argument supplied by a Spanish confusion-pair rule before indexing patternTokens. If the parsed value is less than 1 or greater than the number of pattern tokens, it throws IllegalArgumentException. This is an authoring/data error in the rule XML, not a runtime condition users can fix.

Source

Thrown at languagetool-language-modules/es/src/main/java/org/languagetool/rules/es/ConfusionCheckFilter.java:58

  private static final Pattern CP = Pattern.compile("NC[MFC][PN]000|A..[MFC][PN].|V.P..P.");
  private static final Pattern CS = Pattern.compile("NC[MFC][SN]000|A..[MFC][SN].|V.P..S.");

  @Override
  public RuleMatch acceptRuleMatch(RuleMatch match, Map<String, String> arguments, int patternTokenPos,
                                   AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions) {

    Pattern desiredGenderNumberPattern = null;
    String replacement = null;
    String postag = getRequired("postag", arguments);
    String originalForm = getRequired("form", arguments);
    boolean isAllUppercase = StringTools.isAllUppercase(originalForm);
    boolean isCapitalized = StringTools.isCapitalizedWord(originalForm);
    String form = originalForm.toLowerCase();
    String gendernumberFrom = getOptional("gendernumberFrom", arguments);
    if (gendernumberFrom != null) {
      int i = Integer.parseInt(gendernumberFrom);
      if (i < 1 || i > patternTokens.length) {
        throw new IllegalArgumentException(
            "ConfusionCheckFilter: Index out of bounds in " + match.getRule().getFullId() + ", value: " + i);
      }
      AnalyzedTokenReadings atr = patternTokens[i - 1];
      if (atr.matchesPosTagRegex("[NAPD].+MS.*|V.P..SM")) { desiredGenderNumberPattern = MS;}
      else if (atr.matchesPosTagRegex("[NAPD].+MP.*|V.P..PM")) { desiredGenderNumberPattern = MP;}
      else if (atr.matchesPosTagRegex("[NAPD].+FS.*|V.P..SF")) { desiredGenderNumberPattern = FS;}
      else if (atr.matchesPosTagRegex("[NAPD].+FP.*|V.P..PF")) { desiredGenderNumberPattern = FP;}
      else if (atr.matchesPosTagRegex("[NAPD].+CP.*|V.P..P.")) { desiredGenderNumberPattern = CP;}
      else if (atr.matchesPosTagRegex("[NAPD].+CS.*|V.P..S.")) { desiredGenderNumberPattern = CS;}
    }
    
    if (relevantWords.containsKey(form)) {
      if (relevantWords.get(form).matchesPosTagRegex(postag)) {
        if (desiredGenderNumberPattern != null) {
          Matcher m = desiredGenderNumberPattern.matcher(relevantWords.get(form).getReadings().get(0).getPOSTag());
          if (!m.matches()) {
            return null;
          }

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Fix the gendernumberFrom attribute in the offending rule XML so it points at an existing pattern token (1-based, <= patternTokens.length).
  2. Recount the tokens in the rule's <pattern> (including any skipped tokens per the filter's counting convention) and renumber.
  3. Check the rule id in the message against the Spanish confusion rules and run the rule tests to verify the fix.

Example fix

// before (rule XML)
<filter class="org.languagetool.rules.es.ConfusionCheckFilter" args="... gendernumberFrom:5 ..."/>
// after (pattern only has 4 tokens)
<filter class="org.languagetool.rules.es.ConfusionCheckFilter" args="... gendernumberFrom:2 ..."/>
Defensive patterns

Strategy: validation

Validate before calling

int i = Integer.parseInt(arguments.get("gendernumberFrom"));
if (i < 1 || i > patternTokens.length) {
  throw new IllegalArgumentException("gendernumberFrom=" + i + " out of range 1.." + patternTokens.length + " in rule " + ruleFullId);
}

Prevention

When it happens

Trigger: A Spanish confusion rule XML declares gendernumberFrom="N" where N < 1 or N exceeds the count of tokens in the rule's pattern; acceptRuleMatch parses it with Integer.parseInt and the bounds check fails.

Common situations: Editing or adding Spanish confusion pairs data and mis-numbering the gendernumberFrom token index (1-based); a rule pattern that was shortened after the attribute was written; porting a rule between rules with different token counts.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/4d0b547fe8336921. Report an issue: GitHub.