languagetool-org/languagetool · error · RuntimeException
<antipattern>s can only contain <example>s without errors (i
Error message
<antipattern>s can only contain <example>s without errors (i.e. no 'correction=...').
What it means
Anti-patterns describe texts that must NOT match, so they may only contain correct <example> elements. An <example> with a correction attribute (i.e. an incorrect example with a fix) inside an <antipattern> is invalid and throws this RuntimeException.
Source
Thrown at languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleHandler.java:616
rulegroupAntiPatterns.add(rule);
}
tokenCounter = 0;
inAntiPattern = false;
endPos = -1;
startPos = -1;
inAntiPatternExample = false;
xmlLineNumberAntiPattern = -1;
break;
case EXAMPLE:
if (inAntiPatternExample) {
antipatternExamples.add(new CorrectExample(antiPatternExample.toString()));
} else if (inAntiPatternForRuleGroupExample) {
antipatternForRuleGroupsExamples.add(new CorrectExample(antiPatternForRuleGroupExample.toString()));
} else if (inCorrectExample) {
correctExamples.add(new CorrectExample(correctExample.toString()));
} else if (inIncorrectExample) {
if (inAntiPattern) {
throw new RuntimeException("<antipattern>s can only contain <example>s without errors (i.e. no 'correction=...'). " +
"Rule id: " + id + "[" + subId + "], antipattern no " + antiPatternCounter);
}
IncorrectExample example;
if (exampleCorrection == null) {
example = new IncorrectExample(incorrectExample.toString());
} else {
List<String> corrections = new ArrayList<>(Arrays.asList(exampleCorrection.toString().split("\\|")));
if (exampleCorrection.toString().endsWith("|")) { // suggestions plus an empty suggestion (split() will ignore trailing empty items)
corrections.add("");
}
example = new IncorrectExample(incorrectExample.toString(), corrections);
}
incorrectExamples.add(example);
} else if (inErrorTriggerExample) {
errorTriggeringExamples.add(new ErrorTriggeringExample(errorTriggerExample.toString()));
}
inCorrectExample = false;
inIncorrectExample = false;View on GitHub (pinned to 2e990059ce)
Solutions
- Remove the correction attribute from the <example> inside the <antipattern> so it is a plain error-free example
- Or delete the example from the antipattern entirely
- Or move the example to the rule's own <example> section if it is actually an incorrect example
Example fix
// before <antipattern> <example correction="fixed">bad text</example> </antipattern> // after <antipattern> <example>good text</example> </antipattern>
Defensive patterns
Strategy: validation
Validate before calling
// Ensure no example inside antipattern has a correction attribute
NodeList anti = doc.getElementsByTagName("antipattern");
for (int i = 0; i < anti.getLength(); i++) {
NodeList kids = anti.item(i).getChildNodes();
for (int j = 0; j < kids.getLength(); j++) {
Node n = kids.item(j);
if ("example".equals(n.getNodeName()) && n.getAttributes().getNamedItem("correction") != null)
throw new IllegalStateException("correction example inside antipattern");
}
} Try / catch
try { loader.parse(ruleXml, lang); } catch (RuntimeException e) { if (e.getMessage().contains("<antipattern>s can only contain")) { log.error("Remove correction from antipattern example"); } throw e; } Prevention
- Remember antipatterns accept only error-free examples
- Copy examples carefully when moving them between rule sections
- Lint for correction= inside antipattern blocks
When it happens
Trigger: endElement closes an <example> with correction attribute while inAntiPattern is true; thrown with rule id, subId and the antipattern counter identifying the offending element.
Common situations: Copy-pasting an incorrect example with correction="..." from a normal rule into an antipattern block; misunderstanding that antipatterns only accept error-free examples.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- <regexp> rules currently cannot be used together with <antip
- id is null for rule with name '
- '<marker>' may not be nested in rule '
- Neither '<pattern>' tokens nor '<regexp>' is set in rule '
- Cannot activate rule '
AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06).
Data as JSON: /api/errors/5eea199ad4c4ee15.
Report an issue: GitHub.