{"record":{"id":"19c6ea9a4653c3df","repo":"alibaba/DataX","slug":"the-length-is-not-an-even-number","errorCode":null,"errorMessage":"The length is not an even number","messagePattern":"The length is not an even number","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/alibaba/datax/common/util/DESCipher.java","lineNumber":221,"sourceCode":"\t\treturn decrypt(new String(src));\n\t}\n\n\tpublic static String byte2hex(byte[] b) {\n\t\tString hs = \"\";\n\t\tString stmp = \"\";\n\t\tfor (int n = 0; n < b.length; n++) {\n\t\t\tstmp = (Integer.toHexString(b[n] & 0XFF));\n\t\t\tif (stmp.length() == 1)\n\t\t\t\ths = hs + \"0\" + stmp;\n\t\t\telse\n\t\t\t\ths = hs + stmp;\n\t\t}\n\t\treturn hs.toUpperCase();\n\t}\n\n\tpublic static byte[] hex2byte(byte[] b) {\n\t\tif ((b.length % 2) != 0)\n\t\t\tthrow new IllegalArgumentException(\"The length is not an even number\");\n\t\tbyte[] b2 = new byte[b.length / 2];\n\t\tfor (int n = 0; n < b.length; n += 2) {\n\t\t\tString item = new String(b, n, 2);\n\t\t\tb2[n / 2] = (byte) Integer.parseInt(item, 16);\n\t\t}\n\t\treturn b2;\n\t}\n}\n","sourceCodeStart":203,"sourceCodeEnd":230,"githubUrl":"https://github.com/alibaba/DataX/blob/80ec23d5c5328eb90ca364d2749e92dfaf44541e/common/src/main/java/com/alibaba/datax/common/util/DESCipher.java#L203-L230","documentation":"Thrown by DESCipher.hex2byte when the input byte array has an odd number of bytes. The routine decodes a hex string (2 hex chars per byte), so odd-length input cannot be valid hex and is rejected before parsing. This utility sits under DataX's DES-based password encryption/decryption of job configs.","triggerScenarios":"Passing a hex string of odd length to hex2byte — e.g. a truncated ciphertext ('ABC' instead of 'ABCD'), a string with a stripped leading zero, or non-hex data that coincidentally lost a character.","commonSituations":"Encrypted password in the job config was truncated by copy-paste or shell quoting; the leading zero of a byte pair was dropped somewhere in transport; decrypting data that was never hex-encoded by this cipher.","solutions":["Re-copy the full ciphertext into the config without truncation (even number of hex chars)","If a leading zero was stripped, re-encrypt the password to regenerate a clean ciphertext","Ensure the value is produced by the matching encrypt tool/version of DESCipher"],"exampleFix":"// before\npassword: \"E4F1A\" // odd length -> IllegalArgumentException\n// after\npassword: \"E4F1A0\" // or re-encrypt to get a fresh, complete ciphertext","handlingStrategy":"validation","validationCode":"boolean isEvenLengthHex(String s) {\n    return s != null && (s.length() % 2 == 0) && s.matches(\"(?i)[0-9a-f]+\");\n}","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) {\n  if (\"The length is not an even number\".equals(e.getMessage())) {\n    // ciphertext corrupted/truncated: re-encrypt the password and replace it\n  }\n  throw e;\n}","preventionTips":["Copy encrypted values with a single paste action; avoid shell re-quoting that can drop chars","Hex-validate ciphertext before decryption","Regenerate via the encrypt tool when in doubt"],"tags":["datax","crypto","hex","configuration"],"backgroundTag":null,"analyzedSha":"80ec23d5c5328eb90ca364d2749e92dfaf44541e","analyzedAt":"2026-08-14T15:33:51.187Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}