{"record":{"id":"d7e6071d9115c4fc","repo":"redis/jedis","slug":"hashimport-fields-must-not-contain-null","errorCode":null,"errorMessage":"HashImport fields must not contain null","messagePattern":"HashImport fields must not contain null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/HashImport.java","lineNumber":79,"sourceCode":"    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   */\n  public static HashImport of(byte[]... 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[]> copy = new ArrayList<>(fields.length);","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/HashImport.java#L61-L97","documentation":"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.","triggerScenarios":"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).","commonSituations":"Deserialized JSON arrays containing nulls; SQL query results with NULL columns collected into arrays; Optional mishandling producing null elements in a dynamically built list.","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."],"exampleFix":"// before\nHashImport t = HashImport.of(rawFields); // rawFields may contain nulls\n// after\nString[] clean = Arrays.stream(rawFields).filter(Objects::nonNull).toArray(String[]::new);\nHashImport t = HashImport.of(clean);","handlingStrategy":"validation","validationCode":"boolean noNulls = Arrays.stream(fields).noneMatch(Objects::isNull);\nif (!noNulls) { /* filter or reject before HashImport.of */ }","typeGuard":"boolean allNonNull(String[] a) { return a != null && Arrays.stream(a).allMatch(Objects::nonNull); }","tryCatchPattern":"try {\n  HashImport t = HashImport.of(fields);\n} catch (IllegalArgumentException e) {\n  log.warn(\"Null hash field rejected: {}\", e.getMessage());\n}","preventionTips":["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."],"tags":["validation","null-argument","hash-import"],"backgroundTag":"null-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"}