alibaba/DataX · error · IllegalArgumentException
The length is not an even number
Error message
The length is not an even number
What it means
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.
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
Example fix
// before password: "E4F1A" // odd length -> IllegalArgumentException // after password: "E4F1A0" // or re-encrypt to get a fresh, complete ciphertext
Defensive patterns
Strategy: validation
Validate before calling
boolean isEvenLengthHex(String s) {
return s != null && (s.length() % 2 == 0) && s.matches("(?i)[0-9a-f]+");
} Try / catch
catch (IllegalArgumentException e) {
if ("The length is not an even number".equals(e.getMessage())) {
// ciphertext corrupted/truncated: re-encrypt the password and replace it
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- dx_pad first para( ) support l or r
- Failed to create row serializer, unsupported `format` from…
- Failed to parse delimiter: `Hex str format error`
- Failed to parse delimiter: `Hex str is empty`
- Failed to parse delimiter: `Hex str length error`
AI-assisted analysis of alibaba/DataX@80ec23d5c5 (2026-08-14).
Data as JSON: /api/errors/19c6ea9a4653c3df.
Report an issue: GitHub.
Appendix: source
Thrown at common/src/main/java/com/alibaba/datax/common/util/DESCipher.java:221
return decrypt(new String(src));
}
public static String byte2hex(byte[] b) {
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++) {
stmp = (Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs.toUpperCase();
}
public static byte[] hex2byte(byte[] b) {
if ((b.length % 2) != 0)
throw new IllegalArgumentException("The length is not an even number");
byte[] b2 = new byte[b.length / 2];
for (int n = 0; n < b.length; n += 2) {
String item = new String(b, n, 2);
b2[n / 2] = (byte) Integer.parseInt(item, 16);
}
return b2;
}
}
View on GitHub (pinned to 80ec23d5c5)