apache/hadoop · error · IllegalArgumentException
bytes == null
Error message
bytes == null
What it means
StringUtils.byteToHexString(byte[], int, int) renders a byte range as hex and enforces a null precondition: a null array throws IllegalArgumentException('bytes == null') before any iteration. The caller handed it an absent value — typically a digest or buffer that a producer returned as null on failure.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/StringUtils.java:185
sbuf.append(strs[0]);
for (int idx = 1; idx < strs.length; idx++) {
sbuf.append(",");
sbuf.append(strs[idx]);
}
return sbuf.toString();
}
/**
* Given an array of bytes it will convert the bytes to a hex string
* representation of the bytes
* @param bytes bytes.
* @param start start index, inclusively
* @param end end index, exclusively
* @return hex string representation of the byte array
*/
public static String byteToHexString(byte[] bytes, int start, int end) {
if (bytes == null) {
throw new IllegalArgumentException("bytes == null");
}
StringBuilder s = new StringBuilder();
for(int i = start; i < end; i++) {
s.append(format("%02x", bytes[i]));
}
return s.toString();
}
/**
* Same as byteToHexString(bytes, 0, bytes.length).
* @param bytes bytes.
* @return byteToHexString.
*/
public static String byteToHexString(byte bytes[]) {
return byteToHexString(bytes, 0, bytes.length);
}
/**View on GitHub (pinned to 2add963021)
Solutions
- Null-check at the boundary: if (bytes != null) hex = StringUtils.byteToHexString(bytes, 0, bytes.length);
- Fix the producer to return an empty array (or throw) instead of null on failure
- Use Objects.requireNonNull(bytes, "bytes") earlier to fail with your own clearer message
- Prefer byteToHexString(bytes, 0, bytes.length) only after length is validated for the start/end range
Example fix
// before String hex = StringUtils.byteToHexString(digest, 0, digest.length); // digest null on hash failure // after byte[] digest = md != null ? md.digest() : new byte[0]; String hex = StringUtils.byteToHexString(digest, 0, digest.length);
Defensive patterns
Strategy: validation
Validate before calling
if (bytes == null) {
throw new IllegalArgumentException("bytes required for hex conversion");
}
String hex = StringUtils.byteToHexString(bytes, 0, bytes.length); Prevention
- Design byte-array producers (hashers, serializers) to return empty arrays, not null, on no-data
- Null-check at your API boundary before delegating to StringUtils helpers
- Use Objects.requireNonNull(bytes, "bytes") for fail-fast clarity at the call site
When it happens
Trigger: Passing a null byte[] — e.g. messageDigest.digest() result stored without error handling, an uninitialized field, or a map.get(key) miss whose null flows into logging/hex conversion.
Common situations: Checksum/hash helpers that return null on exception; optional binary attributes absent from a metadata map; defensive-logging code that itself NPEs on null input.
Related errors
- null param while calling Method: [{}]
- null param while calling Method: [{}]
- Null protocol
- Path must be absolute: " + path
- Rename dir to self is forbidden
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/410a8350d69cba01.
Report an issue: GitHub.