{"record":{"id":"fec355b3ad14a5ff","repo":"languagetool-org/languagetool","slug":"got-no-rule-match","errorCode":null,"errorMessage":"Got no rule match: ","messagePattern":"Got no rule match: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"languagetool-dev/src/main/java/org/languagetool/dev/archive/ExampleSentenceCorrectionCreator.java","lineNumber":82,"sourceCode":"    }\n    System.err.println(\"Added corrections: \" + addedCorrectionsCount);\n    for (String xmlLine : xmlLines) {\n      System.out.println(xmlLine);\n    }\n  }\n\n  private void checkCorrections(Rule rule, IncorrectExample incorrectExample, List<String> xmlLines, JLanguageTool tool) throws IOException {\n    List<String> corrections = incorrectExample.getCorrections();\n    if (corrections.isEmpty()) {\n      for (Rule r : tool.getAllActiveRules()) {\n        tool.disableRule(r.getId());\n      }\n      tool.enableRule(rule.getId());\n      String incorrectSentence = incorrectExample.getExample().replaceAll(\"</?marker>\", \"\");\n      List<RuleMatch> matches = tool.check(incorrectSentence);\n      System.err.println(\"no corrections: \" + rule.getId() + \", \" + matches.size() + \" matches\");\n      if (matches.isEmpty()) {\n        throw new RuntimeException(\"Got no rule match: \" + incorrectSentence);\n      }\n      List<String> suggestedReplacements = matches.get(0).getSuggestedReplacements();\n      String newAttribute = \"correction=\\\"\" + String.join(\"|\", suggestedReplacements) + \"\\\"\";\n      addAttribute(rule, newAttribute, xmlLines);\n    }\n  }\n\n  // Note: this is a bad hack, we just iterate through the file's lines\n  private void addAttribute(Rule rule, String newAttribute, List<String> xmlLines) {\n    List<Integer> linesToModify = new ArrayList<>();\n    String currentRuleId = null;\n    Pattern pattern = Pattern.compile(\".*id=[\\\"'](.*?)[\\\"'].*\");\n    String expectedSubId = ((AbstractPatternRule) rule).getSubId();\n    int lineCount = 0;\n    int subRuleCount = 0;\n    int modifyCount = 0;\n    boolean inRuleGroup = false;\n    for (String xmlLine : xmlLines) {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-dev/src/main/java/org/languagetool/dev/archive/ExampleSentenceCorrectionCreator.java#L64-L100","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","Check whether the rule was recently edited (pattern, tokens, regexp) and update the example sentence so it still triggers the rule.","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.","If the rule needs a language model (confusion rules), make sure the model directory is configured via JLanguageTool.withLanguageModel or -lm option.","Fix the example data in grammar.xml: replace the incorrect example with one that genuinely triggers the rule."],"exampleFix":"// before\nList<RuleMatch> matches = tool.check(incorrectSentence);\nif (matches.isEmpty()) {\n  throw new RuntimeException(\"Got no rule match: \" + incorrectSentence);\n}\n// after\n// first fix the data: ensure the <example type=\"incorrect\"> sentence\n// in grammar.xml actually matches the rule's pattern, e.g. update\n// <example markup> after editing the rule's <token> or <regexp> list.\n// Optionally guard:\nList<RuleMatch> matches = tool.check(incorrectSentence);\nif (matches.isEmpty()) {\n  System.err.println(\"SKIPPING (rule no longer matches): \" + rule.getId() + \" -> \" + incorrectSentence);\n  continue;\n}","handlingStrategy":"validation","validationCode":"List<RuleMatch> probe = tool.check(incorrectSentence);\nif (probe.isEmpty()) {\n  throw new IllegalStateException(\"Rule \" + rule.getId() + \" no longer matches example: \" + incorrectSentence);\n}","typeGuard":null,"tryCatchPattern":"try {\n  List<RuleMatch> matches = tool.check(incorrectSentence);\n  if (matches.isEmpty()) { /* skip & log rule id */ }\n} catch (RuntimeException e) {\n  System.err.println(\"Skipping example: \" + e.getMessage());\n}","preventionTips":["Keep rule unit tests in sync: every <example type=\"incorrect\"> sentence should also appear in the rule's test class so breakage is caught early","Re-run this dev tool in CI after any grammar.xml pattern change","Assert tool.getAllActiveRules() contains the rule before checking","Use JLanguageTool's trace mode to debug why a rule no longer fires"],"tags":["java","runtime-exception","rule-matching","nlp"],"backgroundTag":"empty-result-set","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}