{"record":{"id":"f0b704470810a5b8","repo":"redis/jedis","slug":"hashimport-fields-must-be-non-null-and-non-empty","errorCode":null,"errorMessage":"HashImport fields must be non-null and non-empty","messagePattern":"HashImport fields must be non-null and non-empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/HashImport.java","lineNumber":74,"sourceCode":"   * time.\n   */\n  private final ConnectionRegistry connections = new ConnectionRegistry();\n\n  private HashImport(String name, List<byte[]> fields) {\n    this.name = name;\n    this.fields = fields;\n  }\n\n  /**\n   * Creates a template from the given {@link String} field names.\n   * @param fields the ordered field names; must be non-empty with no {@code null}, empty, or\n   *          duplicate entries\n   * @return a new, uniquely named template\n   * @since 8.0\n   */\n  public static HashImport of(String... fields) {\n    if (fields == null || fields.length == 0) {\n      throw new IllegalArgumentException(\"HashImport fields must be non-null and non-empty\");\n    }\n    List<byte[]> encoded = new ArrayList<>(fields.length);\n    for (String field : fields) {\n      if (field == null) {\n        throw new IllegalArgumentException(\"HashImport fields must not contain null\");\n      }\n      encoded.add(SafeEncoder.encode(field));\n    }\n    return build(encoded);\n  }\n\n  /**\n   * Creates a template from the given binary field names.\n   * @param fields the ordered field names; must be non-empty with no {@code null}, empty, or\n   *          duplicate entries (duplicates are compared by content).\n   * @return a new, uniquely named template\n   * @since 8.0\n   */","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/HashImport.java#L56-L92","documentation":"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.","triggerScenarios":"Calling HashImport.of() with no arguments; calling HashImport.of(fields) where fields is a null String[]; passing an empty collection's toArray() result.","commonSituations":"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.","solutions":["Ensure at least one field is provided before calling HashImport.of.","Check fields != null && fields.length > 0 caller-side and skip template creation otherwise.","If emptiness is expected, handle it with a separate code path instead of constructing a HashImport."],"exampleFix":"// before\nHashImport template = HashImport.of(fields); // may be empty\n// after\nif (fields != null && fields.length > 0) {\n  HashImport template = HashImport.of(fields);\n}","handlingStrategy":"validation","validationCode":"if (fields == null || fields.length == 0) {\n  throw new IllegalStateException(\"At least one hash field is required\");\n}","typeGuard":"boolean hasFields(String[] f) { return f != null && f.length > 0; }","tryCatchPattern":"try {\n  HashImport t = HashImport.of(fields);\n} catch (IllegalArgumentException e) {\n  log.warn(\"Invalid HashImport fields: {}\", e.getMessage());\n}","preventionTips":["Check array emptiness at the boundary where the field list is assembled.","Treat an empty field set as a distinct business case, not as a valid HashImport.","Use Optional/List wrappers internally and convert to varargs only when non-empty."],"tags":["validation","empty-argument","hash-import"],"backgroundTag":"missing-required-argument","analyzedSha":"6dac31d4c224fb3257c216f3985340c6f500cdcb","analyzedAt":"2026-09-08T04:55:01.204Z","contentChangedAt":"2026-09-08T04:55:01.204Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}