{"record":{"id":"f0da001c367c54a2","repo":"stanfordnlp/CoreNLP","slug":"got-a-close-tag-tag-name-which-does-not-matc","errorCode":null,"errorMessage":"Got a close tag </${tag.name}> which does not match any open tag","messagePattern":"Got a close tag </(.+?)> which does not match any open tag","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java","lineNumber":860,"sourceCode":"          markSingleSentence = true;\n        }\n      }\n\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          }","sourceCodeStart":842,"sourceCodeEnd":878,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/pipeline/CleanXmlAnnotator.java#L842-L878","documentation":"CleanXmlAnnotator strips XML/SGML-style markup from tokenized text while tracking an enclosing-tag stack. When it encounters a close tag </name> while the open-tag stack is empty, there is nothing to match it against; if allowFlawedXml is false it throws IllegalArgumentException, otherwise it logs this warning and skips the stray close tag.","triggerScenarios":"Calling CleanXmlAnnotator.process on a CoreMap whose tokens contain an XML close tag with no preceding matching open tag — e.g., text fragment starting mid-document like '</p>' or an unescaped '<' token that the tokenizer split into a tag-like token.","commonSituations":"Annotating document fragments/excerpts cut from larger XML files; scraping pipeline output with broken markup; tokenizers treating stray '<' '>' characters as XML tokens in plain text.","solutions":["Set the clean.xmlallowFlawedXml option (clean.xmlallowflawedxml=true) to tolerate unmatched tags, turning the exception into a logged warning.","Fix the upstream text so fragments include their opening tags, or escape/remove stray '<'/'>' before tokenization.","Validate/sanitize the XML markup before running the annotator (e.g., with an XML parser or regex repair pass).","Wrap the annotation step in try/catch for IllegalArgumentException if the input is untrusted and skip failing documents."],"exampleFix":"// before\nprops.setProperty(\"clean.xml\", \"true\");\n// throws on '</b>' with no opener\n\n// after\nprops.setProperty(\"clean.xml\", \"true\");\nprops.setProperty(\"clean.xmlallowflawedxml\", \"true\"); // stray close tags are logged and skipped","handlingStrategy":"try-catch","validationCode":"// Quick sanity check for stray close tags before annotation\nint open = 0;\nfor (String tok : tokens) {\n  if (tok.matches(\"<[^/][^>]*>\")) open++;\n  if (tok.matches(\"</[^>]+>\") && --open < 0) throw new IllegalArgumentException(\"Stray close tag: \" + tok);\n}","typeGuard":null,"tryCatchPattern":"// Tolerate malformed markup for untrusted input\ntry {\n  pipeline.annotate(doc);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"close tag\")) {\n    // re-run with clean.xmlallowflawedxml=true or skip document\n  } else {\n    throw e;\n  }\n}","preventionTips":["Set clean.xmlallowflawedxml=true when annotating document fragments or scraped text","Repair or escape raw '<'/'>' characters in plain-text sources before tokenization","Annotate complete documents rather than mid-tag excerpts","Unit-test your preprocessing with representative malformed markup"],"tags":["nlp","xml","annotation","malformed-input"],"backgroundTag":"mismatched-xml-tags","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"}