{"record":{"id":"4e97bb0ce92721af","repo":"stanfordnlp/CoreNLP","slug":"got-a-close-tag-tag-name-which-does-not","errorCode":null,"errorMessage":"Got a close tag </\" + tag.name + \"> which does not match any open tag","messagePattern":"Got a close tag </\" \\+ tag\\.name \\+ \"> which does not match any open tag","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java","lineNumber":863,"sourceCode":"\n      if (xmlTagMatcher == null)\n        continue;\n\n      if (tag.isSingleTag) {\n        continue;\n      }\n      // at this point, we can't reuse the \"currentTagSet\" vector\n      // any more, since the current tag set has changed\n      currentTagSet = null;\n      if (tag.isEndTag) {\n        while (true) {\n          if (enclosingTags.isEmpty()) {\n            String mesg = \"Got a close tag </\" + tag.name + \"> which does not match any open tag\";\n            if (allowFlawedXml) {\n              log.warn(mesg);\n              break;\n            } else {\n              throw new IllegalArgumentException(mesg);\n            }\n          }\n          String lastTag = enclosingTags.pop();\n          if (xmlTagMatcher.matcher(lastTag).matches()) {\n            matchDepth--;\n          }\n          if (lastTag.equals(tag.name)) {\n            break;\n          }\n          String mesg = \"Mismatched tags: </\" + tag.name + \"> closed a <\" + lastTag + \"> tag.\";\n          if ( ! allowFlawedXml) {\n            throw new IllegalArgumentException(mesg);\n          } else {\n            log.warn(mesg);\n          }\n        }\n        if (matchDepth < 0) {\n          // this should be impossible, since we already assert that","sourceCodeStart":845,"sourceCodeEnd":881,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java#L845-L881","documentation":"While tokenizing XML in process(), a closing tag </name> arrived when no tags were open. Since the XML is unbalanced, CleanXmlAnnotator throws IllegalArgumentException unless allowFlawedXml is true (in which case it just logs a warning).","triggerScenarios":"Feeding text to the annotator (process / newTokens path) that contains a close tag with no matching open tag, e.g. \"</p>\" appearing before or without \"<p>\", with allowFlawedXml=false.","commonSituations":"Processing HTML/XML snippets or truncated documents where tags were stripped or the document starts mid-element; concatenated fragments where open tags were cut off.","solutions":["Fix or regenerate the input so all XML tags are properly opened and closed.","Set the allowFlawedXml option (clean.allowflawedxml=true) to tolerate unbalanced tags with warnings.","Strip the stray close tags from the input before annotation."],"exampleFix":"// before\nprops.setProperty(\"clean.allowflawedxml\", \"false\");\n// after\nprops.setProperty(\"clean.allowflawedxml\", \"true\");","handlingStrategy":"validation","validationCode":"if (countCloseWithoutOpen(xml)) { /* balance tags or enable allowFlawedXml */ props.setProperty(\"clean.allowflawedxml\", \"true\"); }","typeGuard":null,"tryCatchPattern":"try { pipeline.annotate(annotation); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Got a close tag\")) { annotation = retryWithFlawedXmlAllowed(originalText); } else { throw e; } }","preventionTips":["Validate/balance XML before annotating with CleanXmlAnnotator.","Set clean.allowflawedxml=true for noisy real-world HTML/XML sources.","Sanitize concatenated or truncated documents to remove orphan close tags."],"tags":["stanford-corenlp","cleanxml","xml","malformed-input"],"backgroundTag":"malformed-xml-input","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}