languagetool-org/languagetool · error

Got no rule match:

Error message

Got no rule match: 

What it means

ExampleSentenceCorrectionCreator checks incorrect example sentences against JLanguageTool and expects the enabled rule to produce at least one RuleMatch so corrections can be extracted. When tool.check(incorrectSentence) returns an empty match list, the tool cannot derive suggested replacements, so it throws this RuntimeException. This is a data/precondition failure: the example sentence does not actually trigger the rule.

Source

Thrown at languagetool-dev/src/main/java/org/languagetool/dev/archive/ExampleSentenceCorrectionCreator.java:82

    }
    System.err.println("Added corrections: " + addedCorrectionsCount);
    for (String xmlLine : xmlLines) {
      System.out.println(xmlLine);
    }
  }

  private void checkCorrections(Rule rule, IncorrectExample incorrectExample, List<String> xmlLines, JLanguageTool tool) throws IOException {
    List<String> corrections = incorrectExample.getCorrections();
    if (corrections.isEmpty()) {
      for (Rule r : tool.getAllActiveRules()) {
        tool.disableRule(r.getId());
      }
      tool.enableRule(rule.getId());
      String incorrectSentence = incorrectExample.getExample().replaceAll("</?marker>", "");
      List<RuleMatch> matches = tool.check(incorrectSentence);
      System.err.println("no corrections: " + rule.getId() + ", " + matches.size() + " matches");
      if (matches.isEmpty()) {
        throw new RuntimeException("Got no rule match: " + incorrectSentence);
      }
      List<String> suggestedReplacements = matches.get(0).getSuggestedReplacements();
      String newAttribute = "correction=\"" + String.join("|", suggestedReplacements) + "\"";
      addAttribute(rule, newAttribute, xmlLines);
    }
  }

  // Note: this is a bad hack, we just iterate through the file's lines
  private void addAttribute(Rule rule, String newAttribute, List<String> xmlLines) {
    List<Integer> linesToModify = new ArrayList<>();
    String currentRuleId = null;
    Pattern pattern = Pattern.compile(".*id=[\"'](.*?)[\"'].*");
    String expectedSubId = ((AbstractPatternRule) rule).getSubId();
    int lineCount = 0;
    int subRuleCount = 0;
    int modifyCount = 0;
    boolean inRuleGroup = false;
    for (String xmlLine : xmlLines) {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Verify the rule actually fires on the sentence with a minimal JLanguageTool test; enable tracing or run the rule's unit test to see why it doesn't match.
  2. Check whether the rule was recently edited (pattern, tokens, regexp) and update the example sentence so it still triggers the rule.
  3. Confirm the rule is active: call tool.enableRule(rule.getId()) before check (the code does this) and ensure the rule isn't turned off by default category settings.
  4. If the rule needs a language model (confusion rules), make sure the model directory is configured via JLanguageTool.withLanguageModel or -lm option.
  5. Fix the example data in grammar.xml: replace the incorrect example with one that genuinely triggers the rule.

Example fix

// before
List<RuleMatch> matches = tool.check(incorrectSentence);
if (matches.isEmpty()) {
  throw new RuntimeException("Got no rule match: " + incorrectSentence);
}
// after
// first fix the data: ensure the <example type="incorrect"> sentence
// in grammar.xml actually matches the rule's pattern, e.g. update
// <example markup> after editing the rule's <token> or <regexp> list.
// Optionally guard:
List<RuleMatch> matches = tool.check(incorrectSentence);
if (matches.isEmpty()) {
  System.err.println("SKIPPING (rule no longer matches): " + rule.getId() + " -> " + incorrectSentence);
  continue;
}
Defensive patterns

Strategy: validation

Validate before calling

List<RuleMatch> probe = tool.check(incorrectSentence);
if (probe.isEmpty()) {
  throw new IllegalStateException("Rule " + rule.getId() + " no longer matches example: " + incorrectSentence);
}

Try / catch

try {
  List<RuleMatch> matches = tool.check(incorrectSentence);
  if (matches.isEmpty()) { /* skip & log rule id */ }
} catch (RuntimeException e) {
  System.err.println("Skipping example: " + e.getMessage());
}

Prevention

When it happens

Trigger: Running ExampleSentenceCorrectionCreator over archived rule examples when an <example> sentence marked incorrect no longer matches its rule — e.g. the rule's pattern was changed, the rule was disabled/deactivated by default, the sentence's <marker> span was stripped in a way that breaks matching, or the sentence is spelled correctly after recent corpus edits.

Common situations: Developers refactoring grammar.xml rules (changing tokens, regexp, or inflection lists) so old example sentences stop firing; language data contributors adding examples that never matched; running the tool for a language whose rule requires a language model that isn't configured, so the rule silently yields nothing.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


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