{"record":{"id":"2449599a1d2cfd01","repo":"apache/hadoop","slug":"got-unexpected-tag-end-event-for-while-looking","errorCode":null,"errorMessage":"Got unexpected tag end event for {} while looking for section header tag.","messagePattern":"Got unexpected tag end event for (.+?) while looking for section header tag\\.","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":1775,"sourceCode":"    // Write the HDFSIMG1 magic number which begins the fsimage file.\n    out.write(FSImageUtil.MAGIC_HEADER);\n    // Write a series of fsimage sections.\n    sectionStartOffset = FSImageUtil.MAGIC_HEADER.length;\n    final HashSet<String> unprocessedSections =\n        new HashSet<>(sections.keySet());\n    while (!unprocessedSections.isEmpty()) {\n      XMLEvent ev = expectTag(\"[section header]\", true);\n      if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) {\n        if (ev.asEndElement().getName().getLocalPart().equals(\"fsimage\")) {\n          if(unprocessedSections.size() == 1 && unprocessedSections.contains\n                  (SnapshotDiffSectionProcessor.NAME)){\n            break;\n          }\n          throw new IOException(\"FSImage XML ended prematurely, without \" +\n              \"including section(s) \" + StringUtils.join(\", \",\n              unprocessedSections));\n        }\n        throw new IOException(\"Got unexpected tag end event for \" +\n            ev.asEndElement().getName().getLocalPart() + \" while looking \" +\n            \"for section header tag.\");\n      } else if (ev.getEventType() != XMLStreamConstants.START_ELEMENT) {\n        throw new IOException(\"Expected section header START_ELEMENT; \" +\n            \"got event of type \" + ev.getEventType());\n      }\n      String sectionName = ev.asStartElement().getName().getLocalPart();\n      if (!unprocessedSections.contains(sectionName)) {\n        throw new IOException(\"Unknown or duplicate section found for \" +\n            sectionName);\n      }\n      SectionProcessor sectionProcessor = sections.get(sectionName);\n      if (sectionProcessor == null) {\n        throw new IOException(\"Unknown FSImage section \" + sectionName +\n            \".  Valid section names are [\" +\n            StringUtils.join(\", \", sections.keySet()) + \"]\");\n      }\n      unprocessedSections.remove(sectionName);","sourceCodeStart":1757,"sourceCodeEnd":1793,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L1757-L1793","documentation":"While looking for the next section header inside <fsimage>, the ReverseXML StAX reader received an END_ELEMENT whose name is not fsimage. In valid OIV XML the only end tag that can legally appear at this position is </fsimage> itself, so an unexpected closing tag means the top-level element nesting is broken — typically a stray or duplicated closing tag left behind by editing or splicing.","triggerScenarios":"A top-level stray closing tag (e.g. </INODE> without its opening section), duplicated close tags from copy-paste, a section element opened inside another section and closed outside it, or a SectionProcessor stopping before consuming its own end tag on malformed inner content.","commonSituations":"Hand-merging two OIV XML files; scripts that cut and paste section blocks; XML from a homegrown generator that emits unbalanced tags.","solutions":["Regenerate the XML from the original fsimage via `hdfs oiv -p XML`","Run `xmllint --noout image.xml` — an unmatched closing tag is a well-formedness error and xmllint names the tag and line number","Diff the edited file against pristine OIV output to find where the nesting broke"],"exampleFix":"# before: reconstruct edited XML\nhdfs oiv -p ReverseXML -i edited.xml -o out\n# IOException: Got unexpected tag end event for INODE while looking for section header tag.\n\n# after: locate the mismatch before reconstructing\nxmllint --noout edited.xml\n# edited.xml:12: parser error : Opening and ending tag mismatch: INODE line 5 and INODE","handlingStrategy":"validation","validationCode":"# an unmatched closing tag is a well-formedness error; xmllint names tag and line\nxmllint --noout fsimage.xml\n# or without xmllint:\npython3 -c \"import xml.etree.ElementTree as ET; ET.parse('fsimage.xml')\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always validate OIV XML with xmllint --noout before feeding it to ReverseXML","Prefer regenerating the XML from the fsimage over merging or hand-editing section blocks","When scripting transformations, parse and re-serialize with a real XML library instead of sed/awk"],"tags":["hdfs","offline-image-viewer","xml","stax","fsimage"],"backgroundTag":"malformed-xml-structure","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}