redis/jedis · error · IllegalArgumentException

HashImport fields must be non-null and non-empty

Error message

HashImport fields must be non-null and non-empty

What it means

HashImport.of(String...) throws IllegalArgumentException when the varargs array is null or has zero elements. A HashImport template must contain at least one field, since it is used to import hash entries into Redis; an empty template is meaningless.

Solutions

  1. Ensure at least one field is provided before calling HashImport.of.
  2. Check fields != null && fields.length > 0 caller-side and skip template creation otherwise.
  3. If emptiness is expected, handle it with a separate code path instead of constructing a HashImport.

Example fix

// before
HashImport template = HashImport.of(fields); // may be empty
// after
if (fields != null && fields.length > 0) {
  HashImport template = HashImport.of(fields);
}
Defensive patterns

Strategy: validation

Validate before calling

if (fields == null || fields.length == 0) {
  throw new IllegalStateException("At least one hash field is required");
}

Type guard

boolean hasFields(String[] f) { return f != null && f.length > 0; }

Try / catch

try {
  HashImport t = HashImport.of(fields);
} catch (IllegalArgumentException e) {
  log.warn("Invalid HashImport fields: {}", e.getMessage());
}

Prevention

When it happens

Trigger: Calling HashImport.of() with no arguments; calling HashImport.of(fields) where fields is a null String[]; passing an empty collection's toArray() result.

Common situations: Building field lists dynamically from config or user input that produced nothing; empty map keySet converted to an array; optional feature data absent at runtime leading to a zero-length array.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of redis/jedis@6dac31d4c2 (2026-09-08). Data as JSON: /api/errors/f0b704470810a5b8. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/redis/clients/jedis/HashImport.java:74

   * time.
   */
  private final ConnectionRegistry connections = new ConnectionRegistry();

  private HashImport(String name, List<byte[]> fields) {
    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
   */

View on GitHub (pinned to 6dac31d4c2)