{"record":{"id":"8b8c4e0c42d5161d","repo":"apache/hadoop","slug":"collection-key-can-not-be-null","errorCode":null,"errorMessage":"Collection<Key> can not be null","messagePattern":"Collection<Key> can not be null","errorType":"validation","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java","lineNumber":158,"sourceCode":"    if (key == null) {\n      throw new NullPointerException(\"key can not be null\");\n    }\n\n    int[] h = hash.hash(key);\n    hash.clear();\n\n    for (int i = 0; i < nbHash; i++) {\n      fpVector[h[i]].add(key);\n    }\n  }\n\n  /**\n   * Adds a collection of false positive information to <i>this</i> retouched Bloom filter.\n   * @param coll The collection of false positive.\n   */\n  public void addFalsePositive(Collection<Key> coll) {\n    if (coll == null) {\n      throw new NullPointerException(\"Collection<Key> can not be null\");\n    }\n    \n    for (Key k : coll) {\n      addFalsePositive(k);\n    }\n  }\n\n  /**\n   * Adds a list of false positive information to <i>this</i> retouched Bloom filter.\n   * @param keys The list of false positive.\n   */\n  public void addFalsePositive(List<Key> keys) {\n    if (keys == null) {\n      throw new NullPointerException(\"ArrayList<Key> can not be null\");\n    }\n\n    for (Key k : keys) {\n      addFalsePositive(k);","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java#L140-L176","documentation":"The Collection overload of addFalsePositive first checks the collection reference itself; a null collection throws NullPointerException before any element is read. A non-null collection is then forwarded element-by-element to addFalsePositive(Key), which rejects null elements individually.","triggerScenarios":"rbf.addFalsePositive((Collection<Key>) null); passing a never-initialized field; a method parameter that an upstream branch left null.","commonSituations":"Optional feedback stages that skip building the collection and pass null; fields initialized only inside a conditional; glue code mapping 'absent' to null.","solutions":["Pass Collections.emptyList() when there is nothing to record","Null-check the collection before the call","Initialize collection fields at declaration so they are never null"],"exampleFix":"// before\nrbf.addFalsePositive(coll); // NPE when coll == null\n\n// after\nrbf.addFalsePositive(coll != null ? coll : Collections.<Key>emptyList());","handlingStrategy":"validation","validationCode":"rbf.addFalsePositive(coll != null ? coll : Collections.<Key>emptyList());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make your helpers never return null collections (return empty ones)","Initialize collection fields at declaration","Where 'absent' is meaningful, decide the empty-vs-null policy once at the API edge"],"tags":["hadoop","bloom-filter","java","null-check","collections"],"backgroundTag":"null-argument-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}