{"record":{"id":"054e6b8a3d3c74d8","repo":"apache/hadoop","slug":"expected-tag-end-event-for-expected-but-got-e","errorCode":null,"errorMessage":"Expected tag end event for {expected}, but got: {ev}","messagePattern":"Expected tag end event for (.+?), but got: (.+?)","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":237,"sourceCode":"                \" 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 + \")\");\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) {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java#L219-L255","documentation":"expectTagEnd calls expectTag(expected, true) and requires the returned event to be an END_ELEMENT; when a matching (or [...] -group) START_ELEMENT comes back instead, this IOException fires with the full event printed. Concretely it means the stream opened a new element where a close was required - e.g. an extra <inode> appears after the inode loop finished, at the expectTagEnd(INODE_SECTION_NAME) call at OfflineImageReconstructor.java:604.","triggerScenarios":"More <inode> entries physically present than <numInodes> declares (loop exits, expectTagEnd immediately sees the next START_ELEMENT <inode>); a missing close tag so a sibling start arrives where the section close was expected.","commonSituations":"Appending cloned inodes to a dump without incrementing <numInodes>; automated inserts that append a full element instead of replacing one.","solutions":["Make counts agree: either add the missing </inode> closes or raise <numInodes> to the actual entry count","Check pairing with xmllint --noout (unbalanced tags usually trip well-formedness first)","Regenerate the dump and apply additions through a DOM tool that recomputes counts"],"exampleFix":"<!-- before: 3 entries but numInodes says 2 -->\n<INodeSection><numInodes>2</numInodes>\n  <inode>...</inode><inode>...</inode><inode>...</inode>\n</INodeSection>\n\n<!-- after -->\n<INodeSection><numInodes>3</numInodes>\n  <inode>...</inode><inode>...</inode><inode>...</inode>\n</INodeSection>","handlingStrategy":"validation","validationCode":"# No sibling may appear where the section close belongs: counts must agree exactly\ndeclared=$(xmllint --xpath 'string(//INodeSection/numInodes)' fsimage.xml)\nactual=$(xmllint --xpath 'count(//inode)' fsimage.xml)\n[ \"$declared\" -eq \"$actual\" ] || { echo \"fix numInodes ($declared) to match $actual entries\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Appending cloned entries requires incrementing the section count in the same change","Validate tag pairing with xmllint --noout after any append","Automate insertions with DOM APIs that insert before the closing tag"],"tags":["hdfs","reversexml","xml-tag-mismatch","fsimage"],"backgroundTag":"expected-end-tag-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}