{"record":{"id":"4db1364768bb9c59","repo":"apache/hadoop","slug":"got-unexpected-end-event-while-looking-for-expect","errorCode":null,"errorMessage":"Got unexpected end event while looking for {expected}","messagePattern":"Got unexpected end event while looking 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":209,"sourceCode":"      try {\n        ev = events.nextEvent();\n      } catch (XMLStreamException e) {\n        throw new IOException(\"Expecting \" + expected +\n            \", but got XMLStreamException\", e);\n      }\n      switch (ev.getEventType()) {\n      case XMLEvent.ATTRIBUTE:\n        throw new IOException(\"Got unexpected attribute: \" + ev);\n      case XMLEvent.CHARACTERS:\n        if (!ev.asCharacters().isWhiteSpace()) {\n          throw new IOException(\"Got unxpected characters while \" +\n              \"looking for \" + expected + \": \" +\n              ev.asCharacters().getData());\n        }\n        break;\n      case XMLEvent.END_ELEMENT:\n        if (!allowEnd) {\n          throw new IOException(\"Got unexpected end event \" +\n              \"while looking for \" + expected);\n        }\n        return ev;\n      case XMLEvent.START_ELEMENT:\n        if (!expected.startsWith(\"[\")) {\n          if (!ev.asStartElement().getName().getLocalPart().\n                equals(expected)) {\n            throw new IOException(\"Failed to find <\" + expected + \">; \" +\n                \"got \" + ev.asStartElement().getName().getLocalPart() +\n                \" instead.\");\n          }\n        }\n        return ev;\n      default:\n        // Ignore other event types like comment, etc.\n        if (LOG.isTraceEnabled()) {\n          LOG.trace(\"Skipping XMLEvent of type \" +\n              ev.getEventType() + \"(\" +  ev + \")\");","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L191-L227","documentation":"expectTag(expected, allowEnd=false) throws when an END_ELEMENT arrives while a specific start tag was mandatory. In this reconstructor it typically fires when a section closes before a required child appears - e.g. </INodeSection> arrives while the reader is still looking for the <inode> entries that <numInodes> promised (the expectTag(INODE_SECTION_INODE, false) call at OfflineImageReconstructor.java:595).","triggerScenarios":"ReverseXML after entries were deleted from a section without fixing the section's count field, a closing tag duplicated so the enclosing element ends early, or entries renamed so they no longer match the expected child tag.","commonSituations":"Pruning inodes/snapshots/blocks by editing XML to 'clean up' a namespace; merges of two sections that drop entries but keep counts.","solutions":["Fix the count/structure mismatch: restore the missing child elements or update the section's count (e.g. <numInodes>) so the section closes after them","Use the expected-tag name in the message to jump straight to the broken section","Regenerate the XML and reapply the change as a DOM transformation that keeps counts consistent"],"exampleFix":"<!-- before: numInodes promises 2 but section ends after 1 entry -->\n<INodeSection><lastInodeId>16401</lastInodeId><numInodes>2</numInodes>\n  <inode>...</inode>\n</INodeSection>\n\n<!-- after -->\n<INodeSection><lastInodeId>16401</lastInodeId><numInodes>2</numInodes>\n  <inode>...</inode><inode>...</inode>\n</INodeSection>","handlingStrategy":"validation","validationCode":"# Every count-bearing section must be self-consistent before ReverseXML\ndeclared=$(xmllint --xpath 'string(//INodeSection/numInodes)' fsimage.xml)\nactual=$(xmllint --xpath 'count(//inode)' fsimage.xml)\n[ \"$declared\" = \"$actual\" ] || { echo \"numInodes=$declared but $actual <inode> entries\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When deleting entries from a section, update its count field in the same edit","Do structural prunes with a DOM tool that recomputes counts","Watch for duplicated closing tags after merges"],"tags":["hdfs","reversexml","xml-structure","fsimage"],"backgroundTag":"unexpected-end-tag","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}