{"record":{"id":"ff563550de80e108","repo":"apache/hadoop","slug":"expected-section-header-start-element-got-event-o","errorCode":null,"errorMessage":"Expected section header START_ELEMENT; got event of type {}","messagePattern":"Expected section header START_ELEMENT; got event of type (.+?)","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":1779,"sourceCode":"    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);\n      sectionProcessor.process();\n    }\n\n    // Write the StringTable section to disk.","sourceCodeStart":1761,"sourceCodeEnd":1797,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L1761-L1797","documentation":"At the top level of <fsimage> the ReverseXML reader accepts only a section START_ELEMENT or the final </fsimage> END_ELEMENT; any other StAX event (characters, comment, DTD, entity reference — the numeric XMLStreamConstants type appears in the message) fails here. OIV-generated XML never has stray non-element nodes between sections, so the input was altered after generation or produced by a non-conforming generator.","triggerScenarios":"Text pasted directly between section elements, comments or processing instructions at top level, or an XML filter that left character data behind after stripping elements.","commonSituations":"Annotating OIV XML with notes between sections; sed/awk post-processing that leaves fragments; XML from third-party tools claiming OIV compatibility.","solutions":["Regenerate the XML from the original fsimage with `hdfs oiv -p XML`","Strip stray top-level text/comments; decode the event type from javax.xml.stream.XMLStreamConstants (1=START_ELEMENT, 2=END_ELEMENT, 4=CHARACTERS, 5=COMMENT) to know what to hunt for","Re-serialize through a standard parser (`xmllint --format` or an XML library) to normalize the document"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  int rc = ToolRunner.run(new OfflineImageViewerPB(),\n      new String[]{\"-p\", \"ReverseXML\", \"-i\", xmlPath, \"-o\", outPath});\n} catch (Exception e) {\n  // the StAX event type is in the message (4=CHARACTERS, 5=COMMENT, ...)\n  // stray top-level nodes are an input defect: regenerate, do not retry\n  throw new IllegalArgumentException(\"Invalid OIV XML \" + xmlPath + \": \" + e.getMessage(), e);\n}","preventionTips":["Do not paste text or comments between top-level section elements of OIV XML","Normalize edited XML through a standard parser (xmllint --format) before reconstruction","Regenerate XML from the fsimage whenever its provenance is uncertain"],"tags":["hdfs","offline-image-viewer","xml","stax"],"backgroundTag":"malformed-xml-structure","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}