languagetool-org/languagetool · error · PatternRuleNotFoundException
PatternRuleNotFoundException(ruleId, language)
Error message
PatternRuleNotFoundException(ruleId, language)
What it means
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.
Source
Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/index/Searcher.java:263
indexSearcher.search(query, collector);
} catch (TimeLimitingCollector.TimeExceededException e) {
timeLimitActivated = true;
}
return new PossiblyLimitedTopDocs(topCollector.topDocs(), timeLimitActivated);
}
List<PatternRule> getRuleById(String ruleId, Language language) throws IOException {
List<PatternRule> rules = new ArrayList<>();
JLanguageTool lt = new JLanguageTool(language);
for (Rule rule : lt.getAllRules()) {
if (rule.getId().equals(ruleId) && rule instanceof PatternRule) {
rules.add((PatternRule) rule);
}
}
if (rules.size() > 0) {
return rules;
} else {
throw new PatternRuleNotFoundException(ruleId, language);
}
}
private MatchingSentencesResult findMatchingSentences(IndexSearcher indexSearcher, TopDocs topDocs, JLanguageTool languageTool) throws IOException {
List<MatchingSentence> matchingSentences = new ArrayList<>();
int i = 0;
int docsChecked = 0;
for (ScoreDoc match : topDocs.scoreDocs) {
i++;
if (i < skipHits) {
// needed for paging
continue;
}
Document doc = indexSearcher.doc(match.doc);
String sentence = doc.get(fieldName);
if (sentence == null) {
throw new RuntimeException("No field '" + fieldName + "' found in doc " + match.doc);
}View on GitHub (pinned to 2e990059ce)
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
Example fix
// before java ... --rule Id_Wrong --lang en // after java ... --rule EN_A_VS_AN --lang en
Defensive patterns
Strategy: validation
Validate before calling
List<Rule> all = languageTool.getRelevantRules(...); // or JLanguageTool rule listing
boolean exists = ruleIdsFor(language).contains(ruleId);
if (!exists) { System.err.println("Unknown rule " + ruleId + " for " + language); System.exit(2); } Try / catch
try {
rules = searcher.getRuleById(ruleId, language);
} catch (PatternRuleNotFoundException e) {
System.err.println("Rule not found: " + e.getMessage());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- id is null for rule with name '
- Neither '<pattern>' tokens nor '<regexp>' is set in rule '
- Cannot activate rule '
- Rule '<ruleId>' not found for language <lang> (LanguageTool
- No rules are active. Please make sure your rule ids (<option
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/411526c5d8e080a0.
Report an issue: GitHub.