redis/jedis · error · IllegalArgumentException
HashImport fields must not contain null
Error message
HashImport fields must not contain null
What it means
HashImport.of(String...) throws IllegalArgumentException if any individual field in the varargs array is null. Each field is encoded via SafeEncoder.encode, which cannot accept null, and a null field would corrupt the import template.
Solutions
- Filter nulls before the call: fields list.removeIf(Objects::isNull) or use a stream filter.
- Replace null entries with sensible defaults if a value is genuinely required.
- Validate caller-side that every element is non-null before constructing the HashImport.
Example fix
// before HashImport t = HashImport.of(rawFields); // rawFields may contain nulls // after String[] clean = Arrays.stream(rawFields).filter(Objects::nonNull).toArray(String[]::new); HashImport t = HashImport.of(clean);
Defensive patterns
Strategy: validation
Validate before calling
boolean noNulls = Arrays.stream(fields).noneMatch(Objects::isNull);
if (!noNulls) { /* filter or reject before HashImport.of */ } Type guard
boolean allNonNull(String[] a) { return a != null && Arrays.stream(a).allMatch(Objects::nonNull); } Try / catch
try {
HashImport t = HashImport.of(fields);
} catch (IllegalArgumentException e) {
log.warn("Null hash field rejected: {}", e.getMessage());
} Prevention
- Filter nulls from dynamically collected field lists before calling of().
- Avoid sources that emit null elements (use Optional or defaults when deserializing).
- Keep field arrays fully initialized; prefer List<String> built with add() over fixed-size arrays.
When it happens
Trigger: Calling HashImport.of("a", null, "c"); passing a String[] populated from a sparse source (e.g. a list with nulls from a database or JSON array with null entries).
Common situations: Deserialized JSON arrays containing nulls; SQL query results with NULL columns collected into arrays; Optional mishandling producing null elements in a dynamically built list.
Related errors
- Driver version must not be null
- HashImport fields must be non-null and non-empty
- HashImport fields must not contain empty names
- HashImport fields must not contain duplicates
- Path cannot be null.
AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08).
Data as JSON: /api/errors/d7e6071d9115c4fc.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/redis/clients/jedis/HashImport.java:79
this.name = name;
this.fields = fields;
}
/**
* Creates a template from the given {@link String} field names.
* @param fields the ordered field names; must be non-empty with no {@code null}, empty, or
* duplicate entries
* @return a new, uniquely named template
* @since 8.0
*/
public static HashImport of(String... fields) {
if (fields == null || fields.length == 0) {
throw new IllegalArgumentException("HashImport fields must be non-null and non-empty");
}
List<byte[]> encoded = new ArrayList<>(fields.length);
for (String field : fields) {
if (field == null) {
throw new IllegalArgumentException("HashImport fields must not contain null");
}
encoded.add(SafeEncoder.encode(field));
}
return build(encoded);
}
/**
* Creates a template from the given binary field names.
* @param fields the ordered field names; must be non-empty with no {@code null}, empty, or
* duplicate entries (duplicates are compared by content).
* @return a new, uniquely named template
* @since 8.0
*/
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);View on GitHub (pinned to 6dac31d4c2)