{"record":{"id":"d001ed15bef8a903","repo":"apache/hadoop","slug":"value-can-not-be-null","errorCode":null,"errorMessage":"value can not be null","messagePattern":"value can not be null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/Key.java","lineNumber":108,"sourceCode":"\n  /**\n   * Constructor.\n   * <p>\n   * Builds a key with a specified weight.\n   * @param value The value of <i>this</i> key.\n   * @param weight The weight associated to <i>this</i> key.\n   */\n  public Key(byte[] value, double weight) {\n    set(value, weight);\n  }\n\n  /**\n   * @param value value.\n   * @param weight weight.\n   */\n  public void set(byte[] value, double weight) {\n    if (value == null) {\n      throw new IllegalArgumentException(\"value can not be null\");\n    }\n    this.bytes = value;\n    this.weight = weight;\n  }\n  \n  /** @return byte[] The value of <i>this</i> key. */\n  public byte[] getBytes() {\n    return this.bytes;\n  }\n\n  /** @return Returns the weight associated to <i>this</i> key. */\n  public double getWeight() {\n    return weight;\n  }\n\n  /**\n   * Increments the weight of <i>this</i> key with a specified value. \n   * @param weight The increment.","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/Key.java#L90-L126","documentation":"org.apache.hadoop.util.bloom.Key is the byte-array wrapper that all Hadoop Bloom filter classes (BloomFilter, RetouchedBloomFilter, CountingBloomFilter, DynamicBloomFilter) hash. Both constructors delegate to set(byte[], double), which rejects a null byte array with IllegalArgumentException because the hash functions must read actual bytes. A null value here is always a caller bug, never filter state.","triggerScenarios":"new Key(null), new Key(null, 1.0), or key.set(null, w); feeding filter.add()/membershipTest() with a byte[] that came back null from a map lookup, an unset deserialized field, or a failed conversion.","commonSituations":"Bulk-building MapFile/SetFile filters from records where a field is missing; Writable round-trips that skip writing empty arrays so readFields leaves the field null; refactors that turn a lookup into a null-returning one.","solutions":["Null-check the byte[] where it enters your code and skip/log the record instead of constructing a Key","Trace the producer of the null (map.get() miss, unset field after readFields) and fix it there; the Key class is only the messenger","If an 'empty' key is meaningful in your model, encode it explicitly as new byte[0] rather than null"],"exampleFix":"// before\nfilter.add(new Key(bytes)); // throws IllegalArgumentException when bytes == null\n\n// after\nif (bytes == null) {\n  LOG.warn(\"null key bytes; skipping record\");\n  continue;\n}\nfilter.add(new Key(bytes));","handlingStrategy":"validation","validationCode":"if (bytes == null) {\n  LOG.warn(\"null key bytes; skipping record\");\n  continue;\n}\nfilter.add(new Key(bytes));","typeGuard":"static boolean hasKeyBytes(byte[] bytes) {\n  return bytes != null;\n}","tryCatchPattern":"try {\n  filter.add(new Key(bytes));\n} catch (IllegalArgumentException e) {\n  throw new IllegalArgumentException(\"null key bytes for record \" + recordId, e);\n}","preventionTips":["Never pass raw map.get() results straight into new Key()","Validate key bytes at record-parse time, closest to the data source","Log and count null keys as a data-quality signal instead of crashing the filter build"],"tags":["hadoop","bloom-filter","java","null-check","constructor"],"backgroundTag":"null-argument-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}