{"record":{"id":"0b659c2ede54fbf7","repo":"apache/hadoop","slug":"key-can-not-be-null-0b659c","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":201,"sourceCode":"   */\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)) {\n      throw new IllegalArgumentException(\"Key is not a member\");\n    }\n\n    int index = 0;\n    int[] h = hash.hash(k);\n\n    switch(scheme) {\n\n    case RANDOM:\n      index = randomRemove();\n      break;\n    \n    case MINIMUM_FN:\n      index = minimumFnRemove(h);\n      break;","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java#L183-L219","documentation":"selectiveClearing(Key k, short scheme) retouches the filter for one false positive: it hashes the key and clears one bit according to the scheme. The null check throws NullPointerException before hashing because there is no key to retouch.","triggerScenarios":"rbf.selectiveClearing(null, RemoveScheme.RANDOM); retouch loops pulling keys from a queue that uses null as a poison pill; calling with a lookup result without a presence check.","commonSituations":"Producer/consumer retouch pipelines; tests that stub the key source with null; null-means-done conventions carried over from older loop code.","solutions":["Null-check keys as they leave the queue and stop or skip on null","Use an explicit shutdown sentinel object instead of null","Guard at the call site: if (k != null) rbf.selectiveClearing(k, scheme)"],"exampleFix":"// before\nrbf.selectiveClearing(queue.take(), RemoveScheme.RANDOM); // NPE if take() returns null\n\n// after\nKey k = queue.take();\nif (k != null) {\n  rbf.selectiveClearing(k, RemoveScheme.RANDOM);\n}","handlingStrategy":"validation","validationCode":"Key k = queue.poll();\nif (k == null) {\n  break; // or continue, per your pipeline semantics\n}\nrbf.selectiveClearing(k, RemoveScheme.RATIO);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use an explicit shutdown sentinel object instead of null in queues","Guard keys at the point they leave the producer, not deep in the consumer","Validate the whole key source in unit tests with null-inclusive fixtures"],"tags":["hadoop","bloom-filter","java","null-check"],"backgroundTag":"null-argument-exception","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}