redis/jedis · error · IllegalArgumentException
HashImport fields must not contain empty names
Error message
HashImport fields must not contain empty names
What it means
HashImport.build (invoked from both of() overloads) throws IllegalArgumentException when any field is a zero-length byte array. Empty hash field names are not valid Redis hash fields, so the library rejects them while finalizing the template.
Solutions
- Filter out empty entries: drop fields where field == null || field.length == 0 before calling of().
- Trim/validate string inputs so no empty strings reach HashImport.of.
- Check binary sources for truncation that yields zero-length buffers.
Example fix
// before
String[] parts = spec.split(","); // may include ""
HashImport t = HashImport.of(parts);
// after
String[] parts = Arrays.stream(spec.split(",")).map(String::trim).filter(s -> !s.isEmpty()).toArray(String[]::new);
HashImport t = HashImport.of(parts); Defensive patterns
Strategy: validation
Validate before calling
boolean noEmpties = Arrays.stream(fields).allMatch(f -> f != null && !f.trim().isEmpty());
if (!noEmpties) { /* filter empties before HashImport.of */ } Type guard
boolean nonEmpty(byte[] b) { return b != null && b.length > 0; } Try / catch
try {
HashImport t = HashImport.of(fields);
} catch (IllegalArgumentException e) {
log.warn("Empty hash field name rejected: {}", e.getMessage());
} Prevention
- Trim and filter string fields before passing them to of().
- Watch for split()-produced empty tokens when parsing field specs.
- Check binary reads for truncation that yields zero-length arrays.
When it happens
Trigger: Calling HashImport.of("") or HashImport.of(new byte[0]); string fields that are empty after encoding produce byte[0] and fail in build.
Common situations: Empty strings from split() results (e.g. "a,,b".split(",") style logic or trailing delimiters); blank config values; truncated binary reads producing zero-length buffers.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- must not be empty
- HashImport fields must be non-null and non-empty
- HashImport fields must not contain null
- HashImport fields must not contain duplicates
- DriverInfo must not be null
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/61890829fa3cc089.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/HashImport.java:111
public static HashImport of(byte[]... fields) {
if (fields == null || fields.length == 0) {
throw new IllegalArgumentException("HashImport fields must be non-null and non-empty");
}
List<byte[]> copy = new ArrayList<>(fields.length);
for (byte[] field : fields) {
if (field == null) {
throw new IllegalArgumentException("HashImport fields must not contain null");
}
copy.add(field.clone()); // clone so later caller mutation can't alter the template
}
return build(copy);
}
private static HashImport build(List<byte[]> fields) {
Set<ByteBuffer> seen = new HashSet<>();
for (byte[] field : fields) {
if (field.length == 0) {
throw new IllegalArgumentException("HashImport fields must not contain empty names");
}
if (!seen.add(ByteBuffer.wrap(field))) {
throw new IllegalArgumentException("HashImport fields must not contain duplicates");
}
}
return new HashImport(nextName(), Collections.unmodifiableList(fields));
}
/**
* @return {@code true} once {@link #close()} has been called
* @since 8.0
*/
public boolean isDiscarded() {
return discarded;
}
/**
* Discards this template; it must not be used again afterwards. Server-side cleanup is deferredView on GitHub (pinned to 6dac31d4c2)