languagetool-org/languagetool · error · RuntimeException
id is null for rule with name '
Error message
id is null for rule with name '
What it means
PatternRuleHandler parses LanguageTool XML grammar rule files with a SAX handler. Every <rule> must carry an 'id' attribute unless the parser is in relaxedMode; this RuntimeException fires when a rule element ends without an id. Ids are required to reference, enable/disable, and deduplicate rules.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleHandler.java:235
if (YES.equals(premiumFileAttribute)) {
isPremiumRule = true;
} else if (NO.equals(premiumFileAttribute)) {
isPremiumRule = false;
}
} else {
isPremiumRule = false;
}
if (inRuleGroup) {
subId++;
if (id == null) {
id = ruleGroupId;
}
if (name == null) {
name = ruleGroupDescription;
}
}
if (id == null && !relaxedMode) {
throw new RuntimeException("id is null for rule with name '" + name + "'");
}
id = idPrefix != null ? idPrefix + id : id;
if (inRuleGroup && ruleGroupDefaultOff && attrs.getValue(DEFAULT) != null) {
throw new RuntimeException("Rule group " + ruleGroupId + " is off by default, thus a subrule of " + id + " cannot specify 'default=...'. \033[1m Remove 'default=...' from rule group or subrule level in " + ruleGroupId + "!\033[0m");
}
if (inRuleGroup && ruleGroupDefaultTempOff && attrs.getValue(DEFAULT) != null) {
throw new RuntimeException("Rule group " + ruleGroupId + " is off by default, thus a subrule of " + id + " cannot specify 'default=...'. \033[1m Remove 'default=...' from rule group or subrule level in " + ruleGroupId + "!\033[0m");
}
if (inRuleGroup && ruleGroupDefaultOff) {
defaultOff = true;
} else if (inRuleGroup && ruleGroupDefaultTempOff) {
defaultTempOff = true;
} else {
defaultOff = OFF.equals(attrs.getValue(DEFAULT));
defaultTempOff = TEMP_OFF.equals(attrs.getValue(DEFAULT));
}
correctExamples = new ArrayList<>();
antipatternExamples = new ArrayList<>();View on GitHub (pinned to 2e990059ce)
Solutions
- Add an id attribute to the offending <rule> element in the XML file
- If the rule sits in a <rulegroup>, ensure the group has an id and the rule has its own unique sub-id (or set one)
- If parsing third-party/incomplete XML intentionally, enable relaxedMode on the loader so ids are auto-derived
Example fix
// before <rule> <pattern>...</pattern> </rule> // after <rule id="MY_RULE_ID" name="my rule"> <pattern>...</pattern> </rule>
Defensive patterns
Strategy: validation
Validate before calling
// Before loading: sanity-check rule XML for ids
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(ruleXml);
NodeList rules = doc.getElementsByTagName("rule");
for (int i = 0; i < rules.getLength(); i++) {
if (rules.item(i).getAttributes().getNamedItem("id") == null)
throw new IllegalStateException("rule missing id at index " + i);
} Try / catch
try { loader.parse(ruleXml, "en"); } catch (RuntimeException e) { if (e.getMessage().startsWith("id is null")) { log.error("Fix rule XML: add id attribute"); } throw e; } Prevention
- Always give every <rule> an id and name
- Run the rule XML through a schema/DTD check before loading
- Keep template files with id placeholders that fail loudly if unfilled
When it happens
Trigger: Parsing a grammar XML where a <rule> element (or its <rulegroup>) lacks an id attribute while relaxedMode is false. Occurs via PatternRuleLoader.parse(...) or JLanguageTool rule loading.
Common situations: Hand-written or edited custom rule XML missing id="..."; XML where rulegroup-level id inheritance was expected but the rule itself needs one; merging rule files that dropped attributes.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Neither '<pattern>' tokens nor '<regexp>' is set in rule '
- Cannot activate rule '
- Could not load simple replacement data from: " + path + ". E
- Format error in file " + path + ", line: " + line
- '<marker>' may not be nested in rule '
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/9c9e0b34dfb4c7fd.
Report an issue: GitHub.