{"record":{"id":"f1bc18637cd5430a","repo":"apache/hadoop","slug":"e","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"org.apache.hadoop.hdfs.util.XMLUtils.InvalidXmlException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java","lineNumber":5502,"sourceCode":"        Integer.toString(key.getKeyId()));\n    XMLUtils.addSaxString(contentHandler, \"EXPIRY_DATE\",\n        Long.toString(key.getExpiryDate()));\n    if (key.getEncodedKey() != null) {\n      XMLUtils.addSaxString(contentHandler, \"KEY\",\n          Hex.encodeHexString(key.getEncodedKey()));\n    }\n    contentHandler.endElement(\"\", \"\", \"DELEGATION_KEY\");\n  }\n  \n  public static DelegationKey delegationKeyFromXml(Stanza st)\n      throws InvalidXmlException {\n    int keyId = Integer.parseInt(st.getValue(\"KEY_ID\"));\n    long expiryDate = Long.parseLong(st.getValue(\"EXPIRY_DATE\"));\n    byte key[] = null;\n    try {\n      key = Hex.decodeHex(st.getValue(\"KEY\").toCharArray());\n    } catch (DecoderException e) {\n      throw new InvalidXmlException(e.toString());\n    } catch (InvalidXmlException e) {\n    }\n    return new DelegationKey(keyId, expiryDate, key);\n  }\n\n  public static void permissionStatusToXml(ContentHandler contentHandler,\n      PermissionStatus perm) throws SAXException {\n    contentHandler.startElement(\n        \"\", \"\", \"PERMISSION_STATUS\", new AttributesImpl());\n    XMLUtils.addSaxString(contentHandler, \"USERNAME\", perm.getUserName());\n    XMLUtils.addSaxString(contentHandler, \"GROUPNAME\", perm.getGroupName());\n    fsPermissionToXml(contentHandler, perm.getPermission());\n    contentHandler.endElement(\"\", \"\", \"PERMISSION_STATUS\");\n  }\n\n  public static PermissionStatus permissionStatusFromXml(Stanza st)\n      throws InvalidXmlException {\n    Stanza status = st.getChildren(\"PERMISSION_STATUS\").get(0);","sourceCodeStart":5484,"sourceCodeEnd":5520,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSEditLogOp.java#L5484-L5520","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hand-edited or script-mangled XML; hex blobs wrapped by email/chat transfer; tools emitting base64 where hex is required.","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."],"exampleFix":"<!-- before: odd length + trailing whitespace -->\n<KEY>0a1b2c3d4 </KEY>\n\n<!-- after: even-length hex, no whitespace -->\n<KEY>0a1b2c3d04</KEY>","handlingStrategy":"validation","validationCode":"String key = st.getValue(\"KEY\");\nboolean validHex = key != null && key.length() % 2 == 0\n    && key.matches(\"[0-9a-fA-F]+\");\nif (!validHex) {\n  throw new IllegalArgumentException(\"Malformed hex in DELEGATION_KEY/KEY\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  DelegationKey k = FSEditLogOp.delegationKeyFromXml(st);\n} catch (InvalidXmlException e) {\n  // the message embeds DecoderException text: fix the KEY hex before retrying\n}","preventionTips":["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."],"tags":["hdfs","offline-edits-viewer","xml","hex","delegation-key"],"backgroundTag":"malformed-hex-encoding","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}