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.

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)

Solutions

  1. Re-copy the full ciphertext into the config without truncation (even number of hex chars)
  2. If a leading zero was stripped, re-encrypt the password to regenerate a clean ciphertext
  3. 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

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


AI-assisted analysis of alibaba/DataX@80ec23d5c5 (2026-08-14). Data as JSON: /api/errors/19c6ea9a4653c3df. Report an issue: GitHub.