apache/hadoop · error · IOException
Got unexpected end tag for ${name}
Error message
Got unexpected end tag for ${name} What it means
While scanning <SnapshotDiffSection>, ReverseXML read an end-element event whose name was not the section-closing </SnapshotDiffSection>. The section's main loop only accepts <dirDiffEntry>/<fileDiffEntry> start tags and the final section end tag (expectTag with allowEnd=true); any other closing tag aborts the tool. The offending tag name is included in the message.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java:1409
recordSectionLength(SectionName.SNAPSHOT.name());
}
}
private class SnapshotDiffSectionProcessor implements SectionProcessor {
static final String NAME = "SnapshotDiffSection";
@Override
public void process() throws IOException {
// No header for this section type.
LOG.debug("Processing SnapshotDiffSection");
while (true) {
XMLEvent ev = expectTag("[diff start tag]", true);
if (ev.isEndElement()) {
String name = ev.asEndElement().getName().getLocalPart();
if (name.equals(SNAPSHOT_DIFF_SECTION_NAME)) {
break;
}
throw new IOException("Got unexpected end tag for " + name);
}
String tagName = ev.asStartElement().getName().getLocalPart();
if (tagName.equals(SNAPSHOT_DIFF_SECTION_DIR_DIFF_ENTRY)) {
processDirDiffEntry();
} else if (tagName.equals(SNAPSHOT_DIFF_SECTION_FILE_DIFF_ENTRY)) {
processFileDiffEntry();
} else {
throw new IOException("SnapshotDiffSection contained unexpected " +
"tag " + tagName);
}
}
recordSectionLength(SectionName.SNAPSHOT_DIFF.name());
}
private void processDirDiffEntry() throws IOException {
LOG.debug("Processing dirDiffEntry");
DiffEntry.Builder headerBld = DiffEntry.newBuilder();
headerBld.setType(DiffEntry.Type.DIRECTORYDIFF);View on GitHub (pinned to 2add963021)
Solutions
- Run xmllint --noout dump.xml to verify well-formedness, then locate the tag named in the message and fix its open/close balance
- If an entry was deleted, make sure both its start and end tags went with it
- Re-extract the section from the original dump instead of hand-patching
- Regenerate the whole XML with a same-version oiv
Example fix
<!-- before: orphaned close tag after a deleted entry --> <dirDiffEntry>...</dirDiffEntry> </dirDiff> </SnapshotDiffSection> <!-- after --> <dirDiffEntry>...</dirDiffEntry> </SnapshotDiffSection>
Defensive patterns
Strategy: validation
Validate before calling
# well-formedness first, then tag-balance inside SnapshotDiffSection
# xmllint --noout dump.xml
import xml.etree.ElementTree as ET
ET.parse('dump.xml') # raises ParseError on unbalanced tags Try / catch
# catch the CLI failure and surface the named tag
if subprocess.call(['hdfs','oiv','-processor','ReverseXML','-i','dump.xml','-o','out.img']) != 0:
# message names the unexpected end tag; grep the XML for it
... Prevention
- Run xmllint --noout on every edited dump before reconstruction
- Delete whole elements (start+end tags), never line ranges
- Prefer regenerating sections over hand-patching them
- Keep the original dump so edits are always reversible
When it happens
Trigger: An extra, duplicated, or orphaned closing tag inside <SnapshotDiffSection> - e.g. a leftover </dirDiff> after a hand-deleted block, or an element removed but its close tag kept; also mis-nested elements from sed/regex surgery on the XML.
Common situations: Scripted edits that delete diff entries by line range; XML re-serialized by tools that re-order or duplicate close tags; merging sections from two dumps.
Related errors
- SnapshotDiffSection contained unexpected tag ${tagName}
- <dirDiffEntry> contained no <inodeId> entry.
- <dirDiffEntry> contained no <count> entry.
- Only read ${actualDiffs + 1} diffs out of ${expectedDiffs}
- Expected to find <childrenSize> in <dirDiff> section.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/2a5629f1b52f833c.
Report an issue: GitHub.