{"record":{"id":"411526c5d8e080a0","repo":"languagetool-org/languagetool","slug":"patternrulenotfoundexception-ruleid-language","errorCode":null,"errorMessage":"PatternRuleNotFoundException(ruleId, language)","messagePattern":"PatternRuleNotFoundException\\(ruleId, language\\)","errorType":"exception","errorClass":"PatternRuleNotFoundException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java","lineNumber":263,"sourceCode":"      indexSearcher.search(query, collector);\n    } catch (TimeLimitingCollector.TimeExceededException e) {\n      timeLimitActivated = true;\n    }\n    return new PossiblyLimitedTopDocs(topCollector.topDocs(), timeLimitActivated);\n  }\n\n  List<PatternRule> getRuleById(String ruleId, Language language) throws IOException {\n    List<PatternRule> rules = new ArrayList<>();\n    JLanguageTool lt = new JLanguageTool(language);\n    for (Rule rule : lt.getAllRules()) {\n      if (rule.getId().equals(ruleId) && rule instanceof PatternRule) {\n        rules.add((PatternRule) rule);\n      }\n    }\n    if (rules.size() > 0) {\n      return rules;\n    } else {\n      throw new PatternRuleNotFoundException(ruleId, language);\n    }\n  }\n\n  private MatchingSentencesResult findMatchingSentences(IndexSearcher indexSearcher, TopDocs topDocs, JLanguageTool languageTool) throws IOException {\n    List<MatchingSentence> matchingSentences = new ArrayList<>();\n    int i = 0;\n    int docsChecked = 0;\n    for (ScoreDoc match : topDocs.scoreDocs) {\n      i++;\n      if (i < skipHits) {\n        // needed for paging\n        continue;\n      }\n      Document doc = indexSearcher.doc(match.doc);\n      String sentence = doc.get(fieldName);\n      if (sentence == null) {\n        throw new RuntimeException(\"No field '\" + fieldName + \"' found in doc \" + match.doc);\n      }","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java#L245-L281","documentation":"getRuleById looks up pattern rules by their ID for the given language and throws PatternRuleNotFoundException when no rule with that ID resolves. It means the requested rule ID does not exist (or is not a PatternRule) in the loaded rule set for that language.","triggerScenarios":"Passing a ruleId on the command line (main) that no PatternRule matches for the specified language — typo, wrong language, or a rule that exists only in a newer/older LanguageTool version.","commonSituations":"CLI invocation of the Wikipedia indexing/search tooling with a misspelled rule id; specifying a rule for a language other than the one loaded; rule removed/renamed after a LanguageTool upgrade.","solutions":["Check the rule ID spelling against the language's rule definitions","Verify the language passed matches the language the rule belongs to","List available rules for the language and pick a valid ID","If the rule was renamed in a LanguageTool upgrade, update the ID"],"exampleFix":"// before\njava ... --rule Id_Wrong --lang en\n// after\njava ... --rule EN_A_VS_AN --lang en","handlingStrategy":"validation","validationCode":"List<Rule> all = languageTool.getRelevantRules(...); // or JLanguageTool rule listing\nboolean exists = ruleIdsFor(language).contains(ruleId);\nif (!exists) { System.err.println(\"Unknown rule \" + ruleId + \" for \" + language); System.exit(2); }","typeGuard":null,"tryCatchPattern":"try {\n  rules = searcher.getRuleById(ruleId, language);\n} catch (PatternRuleNotFoundException e) {\n  System.err.println(\"Rule not found: \" + e.getMessage());\n}","preventionTips":["Copy rule IDs from the language's XML rules, never from memory","Pin the LanguageTool version and re-check IDs after upgrades","Verify rule belongs to the selected language"],"tags":["rules","languagetool","not-found"],"backgroundTag":"record-not-found","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"}