{"record":{"id":"9ae5a359a284a900","repo":"apache/hadoop","slug":"expected-tag-end-event-for-expected-but-got-tag","errorCode":null,"errorMessage":"Expected tag end event for {expected}, but got tag end event for {tag}","messagePattern":"Expected tag end event for (.+?), but got tag end event for (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java","lineNumber":243,"sourceCode":"        if (LOG.isTraceEnabled()) {\n          LOG.trace(\"Skipping XMLEvent of type \" +\n              ev.getEventType() + \"(\" +  ev + \")\");\n        }\n        break;\n      }\n    }\n  }\n\n  private void expectTagEnd(String expected) throws IOException {\n    XMLEvent ev = expectTag(expected, true);\n    if (ev.getEventType() != XMLStreamConstants.END_ELEMENT) {\n      throw new IOException(\"Expected tag end event for \" + expected +\n            \", but got: \" + ev);\n    }\n    if (!expected.startsWith(\"[\")) {\n      String tag = ev.asEndElement().getName().getLocalPart();\n      if (!tag.equals(expected)) {\n        throw new IOException(\"Expected tag end event for \" + expected +\n        \", but got tag end event for \" + tag);\n      }\n    }\n  }\n\n  private static class Node {\n    private static final String EMPTY = \"\";\n    HashMap<String, LinkedList<Node>> children;\n    String val = EMPTY;\n\n    void addChild(String key, Node node) {\n      if (children == null) {\n        children = new HashMap<>();\n      }\n      LinkedList<Node> cur = children.get(key);\n      if (cur == null) {\n        cur = new LinkedList<>();\n        children.put(key, cur);","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L225-L261","documentation":"After expectTagEnd receives an END_ELEMENT it checks that the closing tag's local name equals the expected literal (the check is skipped for [...] group names). A different closing name means the document's end tags do not line up with the element the reconstructor is closing; some StAX configurations pass mismatched end tags through as events rather than raising XMLStreamException, which is how this state becomes reachable.","triggerScenarios":"An element closed with the wrong name - e.g. </file> where </inode> was required - after a start tag was renamed without its closer, or a subtree spliced from another dump keeping its original closing tags.","commonSituations":"Find/replace renames that hit only one tag of the pair; hand-built sections assembled by copying fragments.","solutions":["Rename the closing tag to match its start tag - the message names both","Run xmllint --noout first; it rejects most mismatched end tags before ReverseXML runs","Regenerate the XML instead of patching tag names"],"exampleFix":"<!-- before -->\n<inode><id>16386</id></file>\n\n<!-- after -->\n<inode><id>16386</id></inode>","handlingStrategy":"validation","validationCode":"xmllint --noout fsimage.xml || { echo 'fix the reported mismatched/unclosed tags first'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rename start and end tags together (regex on the pair, not single names)","Reject hand-spliced subtrees unless their tags round-trip through xmllint","Prefer regenerating over renaming tags"],"tags":["hdfs","reversexml","mismatched-closing-tag","fsimage"],"backgroundTag":"mismatched-closing-tag","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}