apache/hadoop · error · IOException
Expected tag end event for {expected}, but got tag end event
Error message
Expected tag end event for {expected}, but got tag end event for {tag} What it means
After expectTagEnd receives an END_ELEMENT it checks that the closing tag's local name equals the expected literal (the check is skipped for [...] group names). A different closing name means the document's end tags do not line up with the element the reconstructor is closing; some StAX configurations pass mismatched end tags through as events rather than raising XMLStreamException, which is how this state becomes reachable.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java:243
if (LOG.isTraceEnabled()) {
LOG.trace("Skipping XMLEvent of type " +
ev.getEventType() + "(" + ev + ")");
}
break;
}
}
}
private void expectTagEnd(String expected) throws IOException {
XMLEvent ev = expectTag(expected, true);
if (ev.getEventType() != XMLStreamConstants.END_ELEMENT) {
throw new IOException("Expected tag end event for " + expected +
", but got: " + ev);
}
if (!expected.startsWith("[")) {
String tag = ev.asEndElement().getName().getLocalPart();
if (!tag.equals(expected)) {
throw new IOException("Expected tag end event for " + expected +
", but got tag end event for " + tag);
}
}
}
private static class Node {
private static final String EMPTY = "";
HashMap<String, LinkedList<Node>> children;
String val = EMPTY;
void addChild(String key, Node node) {
if (children == null) {
children = new HashMap<>();
}
LinkedList<Node> cur = children.get(key);
if (cur == null) {
cur = new LinkedList<>();
children.put(key, cur);View on GitHub (pinned to 2add963021)
Solutions
- Rename the closing tag to match its start tag - the message names both
- Run xmllint --noout first; it rejects most mismatched end tags before ReverseXML runs
- Regenerate the XML instead of patching tag names
Example fix
<!-- before --> <inode><id>16386</id></file> <!-- after --> <inode><id>16386</id></inode>
Defensive patterns
Strategy: validation
Validate before calling
xmllint --noout fsimage.xml || { echo 'fix the reported mismatched/unclosed tags first'; exit 1; } Prevention
- Rename start and end tags together (regex on the pair, not single names)
- Reject hand-spliced subtrees unless their tags round-trip through xmllint
- Prefer regenerating over renaming tags
When it happens
Trigger: An element closed with the wrong name - e.g. </file> where </inode> was required - after a start tag was renamed without its closer, or a subtree spliced from another dump keeping its original closing tags.
Common situations: Find/replace renames that hit only one tag of the pair; hand-built sections assembled by copying fragments.
Related errors
- Expecting {expected}, but got XMLStreamException
- Got unexpected attribute: {ev}
- Got unxpected characters while looking for {expected}: {ev.a
- Got unexpected end event while looking for {expected}
- Failed to find <{expected}>; got {ev.asStartElement().getNam
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/9ae5a359a284a900.
Report an issue: GitHub.