languagetool-org/languagetool · error · RuntimeException

Unexpected exception when processing regexp in rule with id

Error message

Unexpected exception when processing regexp in rule with id %s.

What it means

Wrapper exception from the regex rule engine: while applying a regex-based rule to a sentence, an unexpected low-level exception (regex processing, filter evaluation, or suggestion replacement) escaped. The original cause is chained, and the rule id in the message identifies which XML rule triggered it; the error is in the rule definition or its filter, not in the calling code.

Source

Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexPatternRule.java:126

        boolean startsWithUpperCase = patternMatcher.start() == 0 && Character.isUpperCase(text.charAt(patternMatcher.start()));
        RuleMatch ruleMatch = new RuleMatch(this, sentenceObj, markStart, markEnd, patternMatcher.start(), patternMatcher.end(),
                processedMessage, shortMessage, startsWithUpperCase, false, processedSuggestionsOutMsg, true);
        if (regexFilter != null) {
          RegexRuleFilterEvaluator ruleFilterEvaluator = new RegexRuleFilterEvaluator(regexFilter);
          RuleMatch filteredMatch = ruleFilterEvaluator.runFilter(getFilterArguments(), ruleMatch, sentenceObj, patternMatcher);
          if (filteredMatch != null) {
            matches.add(ruleMatch);
          }
        } else {
          matches.add(ruleMatch);
        }

        startPos = patternMatcher.end();
      } catch (IndexOutOfBoundsException e){
        throw new RuntimeException(String.format("Unexpected reference to capturing group in rule with id %s.", this.getFullId()), e);
      } catch (Exception e) {
        throw new RuntimeException(String.format("Unexpected exception when processing regexp in rule with id %s.", this.getFullId()), e);
      }
    }
    return matches.toArray(RuleMatch.EMPTY_ARRAY);
  }

  @NotNull
  private List<Pair<Integer, Integer>> getClausePositionsInMessage(Pattern pattern, String message) {
    Matcher matcher = pattern.matcher(message);
    List<Pair<Integer, Integer>> clausePositionsInMessage = new ArrayList<>();
    while (matcher.find()) {
      clausePositionsInMessage.add(Pair.of(matcher.start(), matcher.end()));
    }
    return clausePositionsInMessage;
  }

  private String processMessage(Matcher matcher, String message, List<Pair<Integer, Integer>> backReferences,
                                List<Pair<Integer, Integer>> suggestions, List<Match> matches) {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Inspect the chained cause exception to identify the underlying failure
  2. Test the rule's regular expression in isolation to find syntax or back-reference errors
  3. If the rule uses a <filter>, verify the filter class and its arguments are correct
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/RegexPatternRule.java:126 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/33dba251202b5f84. Report an issue: GitHub.