{"record":{"id":"61890829fa3cc089","repo":"redis/jedis","slug":"hashimport-fields-must-not-contain-empty-names","errorCode":null,"errorMessage":"HashImport fields must not contain empty names","messagePattern":"HashImport fields must not contain empty names","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/HashImport.java","lineNumber":111,"sourceCode":"  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);\n    for (byte[] field : fields) {\n      if (field == null) {\n        throw new IllegalArgumentException(\"HashImport fields must not contain null\");\n      }\n      copy.add(field.clone()); // clone so later caller mutation can't alter the template\n    }\n    return build(copy);\n  }\n\n  private static HashImport build(List<byte[]> fields) {\n    Set<ByteBuffer> seen = new HashSet<>();\n    for (byte[] field : fields) {\n      if (field.length == 0) {\n        throw new IllegalArgumentException(\"HashImport fields must not contain empty names\");\n      }\n      if (!seen.add(ByteBuffer.wrap(field))) {\n        throw new IllegalArgumentException(\"HashImport fields must not contain duplicates\");\n      }\n    }\n    return new HashImport(nextName(), Collections.unmodifiableList(fields));\n  }\n\n  /**\n   * @return {@code true} once {@link #close()} has been called\n   * @since 8.0\n   */\n  public boolean isDiscarded() {\n    return discarded;\n  }\n\n  /**\n   * Discards this template; it must not be used again afterwards. Server-side cleanup is deferred","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/HashImport.java#L93-L129","documentation":"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.","triggerScenarios":"Calling HashImport.of(\"\") or HashImport.of(new byte[0]); string fields that are empty after encoding produce byte[0] and fail in build.","commonSituations":"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.","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."],"exampleFix":"// before\nString[] parts = spec.split(\",\"); // may include \"\"\nHashImport t = HashImport.of(parts);\n// after\nString[] parts = Arrays.stream(spec.split(\",\")).map(String::trim).filter(s -> !s.isEmpty()).toArray(String[]::new);\nHashImport t = HashImport.of(parts);","handlingStrategy":"validation","validationCode":"boolean noEmpties = Arrays.stream(fields).allMatch(f -> f != null && !f.trim().isEmpty());\nif (!noEmpties) { /* filter empties before HashImport.of */ }","typeGuard":"boolean nonEmpty(byte[] b) { return b != null && b.length > 0; }","tryCatchPattern":"try {\n  HashImport t = HashImport.of(fields);\n} catch (IllegalArgumentException e) {\n  log.warn(\"Empty hash field name rejected: {}\", e.getMessage());\n}","preventionTips":["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."],"tags":["validation","empty-value","hash-import"],"backgroundTag":"empty-required-field","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"}