{"record":{"id":"4801b583202d80c8","repo":"redis/jedis","slug":"hashimport-fields-must-not-contain-duplicates","errorCode":null,"errorMessage":"HashImport fields must not contain duplicates","messagePattern":"HashImport fields must not contain duplicates","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/redis/clients/jedis/HashImport.java","lineNumber":114,"sourceCode":"    }\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\n   * and handled by the client. Idempotent.\n   * @since 8.0\n   */","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/redis/jedis/blob/6dac31d4c224fb3257c216f3985340c6f500cdcb/src/main/java/redis/clients/jedis/HashImport.java#L96-L132","documentation":"HashImport.build throws IllegalArgumentException when the same field appears more than once in the input. Duplicates are detected content-wise via a HashSet of ByteBuffers, ensuring each hash field in the import template is unique.","triggerScenarios":"Calling HashImport.of(\"field\", \"field\"); passing a byte[][] containing content-identical arrays (duplicate detection compares bytes, not references); fields collected from a source that can repeat keys (e.g. concatenated config sections).","commonSituations":"Merging field lists from multiple sources without deduplication; HGETALL-style dumps re-fed as import fields in edge cases; users assuming later entries override earlier ones, but the API forbids duplicates outright.","solutions":["Deduplicate caller-side: Arrays.stream(fields).distinct().toArray(String[]::new) for strings, or a LinkedHashSet<byte[]> wrapped appropriately for binary content.","If merge semantics are needed, build a Map first so later values override earlier ones, then pass unique field names.","Decide on one representative entry per duplicated field before constructing the template."],"exampleFix":"// before\nHashImport t = HashImport.of(fields); // may contain duplicates\n// after\nString[] unique = Arrays.stream(fields).distinct().toArray(String[]::new);\nHashImport t = HashImport.of(unique);","handlingStrategy":"validation","validationCode":"long distinct = Arrays.stream(fields).distinct().count();\nif (distinct != fields.length) { /* deduplicate before HashImport.of */ }","typeGuard":"boolean allDistinct(String[] a) { return a == null || Arrays.stream(a).distinct().count() == a.length; }","tryCatchPattern":"try {\n  HashImport t = HashImport.of(fields);\n} catch (IllegalArgumentException e) {\n  log.warn(\"Duplicate hash field rejected: {}\", e.getMessage());\n}","preventionTips":["Deduplicate field lists (LinkedHashSet or Stream.distinct) before constructing the template.","Use a Map when merge/override semantics are desired, then pass unique keys.","When combining field lists from multiple sources, deduplicate at merge time."],"tags":["validation","duplicate-entries","hash-import"],"backgroundTag":"invalid-argument-value","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"}