{"record":{"id":"2d80d3e0997d9bd8","repo":"apache/hadoop","slug":"key-can-not-be-null-2d80d3","errorCode":null,"errorMessage":"Key[] can not be null","messagePattern":"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":186,"sourceCode":"   * @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);\n    }\n  }\n\n  /**\n   * Adds an array of false positive information to <i>this</i> retouched Bloom filter.\n   * @param keys The array of false positive.\n   */\n  public void addFalsePositive(Key[] keys) {\n    if (keys == null) {\n      throw new NullPointerException(\"Key[] can not be null\");\n    }\n\n    for (int i = 0; i < keys.length; i++) {\n      addFalsePositive(keys[i]);\n    }\n  }\n\n  /**\n   * Performs the selective clearing for a given key.\n   * @param k The false positive key to remove from <i>this</i> retouched Bloom filter.\n   * @param scheme The selective clearing scheme to apply.\n   */\n  public void selectiveClearing(Key k, short scheme) {\n    if (k == null) {\n      throw new NullPointerException(\"Key can not be null\");\n    }\n\n    if (!membershipTest(k)) {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java#L168-L204","documentation":"The array overload throws NullPointerException when the Key[] reference is null. The per-element loop then forwards each slot to addFalsePositive(Key), so a null element inside a non-null array trips the per-key check instead.","triggerScenarios":"rbf.addFalsePositive((Key[]) null); array accumulators that start as null and are only lazily allocated; varargs call sites passing an uninitialized array.","commonSituations":"Accumulator patterns that grow arrays on demand; fixed-size buffers reused across batches where null marks 'not built yet'.","solutions":["Pass new Key[0] when the array is absent","Null-check the array reference before the call","Allocate arrays eagerly while building the batch"],"exampleFix":"// before\nrbf.addFalsePositive(keys); // keys may be null -> NPE\n\n// after\nrbf.addFalsePositive(keys != null ? keys : new Key[0]);","handlingStrategy":"validation","validationCode":"rbf.addFalsePositive(keys != null ? keys : new Key[0]);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Allocate accumulator arrays eagerly when building batches","Null-check array references that come from lazily-built buffers","Remember null elements inside a non-null array still fail the per-key check"],"tags":["hadoop","bloom-filter","java","null-check","arrays"],"backgroundTag":"null-argument-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}