{"record":{"id":"5eea199ad4c4ee15","repo":"languagetool-org/languagetool","slug":"antipattern-s-can-only-contain-example-s-without","errorCode":null,"errorMessage":"<antipattern>s can only contain <example>s without errors (i.e. no 'correction=...'). ","messagePattern":"<antipattern>s can only contain <example>s without errors \\(i\\.e\\. no 'correction=\\.\\.\\.'\\)\\. ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleHandler.java","lineNumber":616,"sourceCode":"          rulegroupAntiPatterns.add(rule);\n        }\n        tokenCounter = 0;\n        inAntiPattern = false;\n        endPos = -1;\n        startPos = -1;\n        inAntiPatternExample = false;\n        xmlLineNumberAntiPattern = -1;\n        break;\n      case EXAMPLE:\n        if (inAntiPatternExample) {\n          antipatternExamples.add(new CorrectExample(antiPatternExample.toString()));\n        } else if (inAntiPatternForRuleGroupExample) {\n          antipatternForRuleGroupsExamples.add(new CorrectExample(antiPatternForRuleGroupExample.toString()));\n        } else if (inCorrectExample) {\n          correctExamples.add(new CorrectExample(correctExample.toString()));\n        } else if (inIncorrectExample) {\n          if (inAntiPattern) {\n            throw new RuntimeException(\"<antipattern>s can only contain <example>s without errors (i.e. no 'correction=...'). \" +\n              \"Rule id: \" + id + \"[\" + subId + \"], antipattern no \" + antiPatternCounter);\n          }\n          IncorrectExample example;\n          if (exampleCorrection == null) {\n            example = new IncorrectExample(incorrectExample.toString());\n          } else {\n            List<String> corrections = new ArrayList<>(Arrays.asList(exampleCorrection.toString().split(\"\\\\|\")));\n            if (exampleCorrection.toString().endsWith(\"|\")) {  // suggestions plus an empty suggestion (split() will ignore trailing empty items)\n              corrections.add(\"\");\n            }\n            example = new IncorrectExample(incorrectExample.toString(), corrections);\n          }\n          incorrectExamples.add(example);\n        } else if (inErrorTriggerExample) {\n          errorTriggeringExamples.add(new ErrorTriggeringExample(errorTriggerExample.toString()));\n        }\n        inCorrectExample = false;\n        inIncorrectExample = false;","sourceCodeStart":598,"sourceCodeEnd":634,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-core/src/main/java/org/languagetool/rules/patterns/PatternRuleHandler.java#L598-L634","documentation":"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.","triggerScenarios":"endElement closes an <example> with correction attribute while inAntiPattern is true; thrown with rule id, subId and the antipattern counter identifying the offending element.","commonSituations":"Copy-pasting an incorrect example with correction=\"...\" from a normal rule into an antipattern block; misunderstanding that antipatterns only accept error-free examples.","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"],"exampleFix":"// before\n<antipattern>\n  <example correction=\"fixed\">bad text</example>\n</antipattern>\n// after\n<antipattern>\n  <example>good text</example>\n</antipattern>","handlingStrategy":"validation","validationCode":"// Ensure no example inside antipattern has a correction attribute\nNodeList anti = doc.getElementsByTagName(\"antipattern\");\nfor (int i = 0; i < anti.getLength(); i++) {\n  NodeList kids = anti.item(i).getChildNodes();\n  for (int j = 0; j < kids.getLength(); j++) {\n    Node n = kids.item(j);\n    if (\"example\".equals(n.getNodeName()) && n.getAttributes().getNamedItem(\"correction\") != null)\n      throw new IllegalStateException(\"correction example inside antipattern\");\n  }\n}","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["Remember antipatterns accept only error-free examples","Copy examples carefully when moving them between rule sections","Lint for correction= inside antipattern blocks"],"tags":["xml","antipattern","validation","languagetool"],"backgroundTag":"schema-validation-failed","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"}