apache/hadoop · error · org.apache.hadoop.hdfs.util.XMLUtils.InvalidXmlException
{e}
Error message
{e} What it means
In delegationKeyFromXml(), the KEY element of a DELEGATION_KEY stanza is hex-decoded with Hex.decodeHex(). A DecoderException (odd number of hex digits or non-hex characters) is rethrown as InvalidXmlException carrying the original exception text. The XML input therefore contains a malformed hex-encoded delegation key.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java:5502
Integer.toString(key.getKeyId()));
XMLUtils.addSaxString(contentHandler, "EXPIRY_DATE",
Long.toString(key.getExpiryDate()));
if (key.getEncodedKey() != null) {
XMLUtils.addSaxString(contentHandler, "KEY",
Hex.encodeHexString(key.getEncodedKey()));
}
contentHandler.endElement("", "", "DELEGATION_KEY");
}
public static DelegationKey delegationKeyFromXml(Stanza st)
throws InvalidXmlException {
int keyId = Integer.parseInt(st.getValue("KEY_ID"));
long expiryDate = Long.parseLong(st.getValue("EXPIRY_DATE"));
byte key[] = null;
try {
key = Hex.decodeHex(st.getValue("KEY").toCharArray());
} catch (DecoderException e) {
throw new InvalidXmlException(e.toString());
} catch (InvalidXmlException e) {
}
return new DelegationKey(keyId, expiryDate, key);
}
public static void permissionStatusToXml(ContentHandler contentHandler,
PermissionStatus perm) throws SAXException {
contentHandler.startElement(
"", "", "PERMISSION_STATUS", new AttributesImpl());
XMLUtils.addSaxString(contentHandler, "USERNAME", perm.getUserName());
XMLUtils.addSaxString(contentHandler, "GROUPNAME", perm.getGroupName());
fsPermissionToXml(contentHandler, perm.getPermission());
contentHandler.endElement("", "", "PERMISSION_STATUS");
}
public static PermissionStatus permissionStatusFromXml(Stanza st)
throws InvalidXmlException {
Stanza status = st.getChildren("PERMISSION_STATUS").get(0);View on GitHub (pinned to 2add963021)
Solutions
- Check the KEY value: even length, only 0-9/a-f characters, no whitespace or 0x prefix.
- Regenerate the XML from the binary edits file to get a pristine hex blob.
- Re-encode the key correctly if you must edit: lowercase or uppercase hex both work, but digit count must be even.
Example fix
<!-- before: odd length + trailing whitespace --> <KEY>0a1b2c3d4 </KEY> <!-- after: even-length hex, no whitespace --> <KEY>0a1b2c3d04</KEY>
Defensive patterns
Strategy: validation
Validate before calling
String key = st.getValue("KEY");
boolean validHex = key != null && key.length() % 2 == 0
&& key.matches("[0-9a-fA-F]+");
if (!validHex) {
throw new IllegalArgumentException("Malformed hex in DELEGATION_KEY/KEY");
} Try / catch
try {
DelegationKey k = FSEditLogOp.delegationKeyFromXml(st);
} catch (InvalidXmlException e) {
// the message embeds DecoderException text: fix the KEY hex before retrying
} Prevention
- Treat offline-edits XML as machine-generated only.
- Pre-validate hex fields with a length + charset regex.
- Avoid tools that reflow or trim long element content.
When it happens
Trigger: OfflineEditsViewer XML-to-binary conversion where KEY contains whitespace, an odd-length string, a '0x' prefix, or characters outside 0-9a-f; keys truncated or reflowed by copy-paste or line-wrapping when the XML was edited or transferred.
Common situations: Hand-edited or script-mangled XML; hex blobs wrapped by email/chat transfer; tools emitting base64 where hex is required.
Related errors
- can't understand DelegationTokenIdentifier KIND {kind}
- Invalid value for FsAction
- expecting </EDITS>
- you must put <EDITS> at the top of the XML file! Got tag {}
- you must put <EDITS_VERSION> at the top of the XML file! Got
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/f1bc18637cd5430a.
Report an issue: GitHub.