apache/hadoop · error · NullPointerException
Key may not be null
Error message
Key may not be null
What it means
CountingBloomFilter.delete(Key) removes a key by decrementing the counters it previously incremented; it first requires a non-null key and throws NullPointerException('Key may not be null') as an explicit guard. This mirrors add() and membershipTest() in the same class, failing fast with a readable message instead of an opaque NPE from the hashing layer.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/CountingBloomFilter.java:137
long bucketValue = (buckets[wordNum] & bucketMask) >>> bucketShift;
// only increment if the count in the bucket is less than BUCKET_MAX_VALUE
if(bucketValue < BUCKET_MAX_VALUE) {
// increment by 1
buckets[wordNum] = (buckets[wordNum] & ~bucketMask) | ((bucketValue + 1) << bucketShift);
}
}
}
/**
* Removes a specified key from <i>this</i> counting Bloom filter.
* <p>
* <b>Invariant</b>: nothing happens if the specified key does not belong to <i>this</i> counter Bloom filter.
* @param key The key to remove.
*/
public void delete(Key key) {
if(key == null) {
throw new NullPointerException("Key may not be null");
}
if(!membershipTest(key)) {
throw new IllegalArgumentException("Key is not a member");
}
int[] h = hash.hash(key);
hash.clear();
for(int i = 0; i < nbHash; i++) {
// find the bucket
int wordNum = h[i] >> 4; // div 16
int bucketShift = (h[i] & 0x0f) << 2; // (mod 16) * 4
long bucketMask = 15L << bucketShift;
long bucketValue = (buckets[wordNum] & bucketMask) >>> bucketShift;
// only decrement if the count in the bucket is between 0 and BUCKET_MAX_VALUE
if(bucketValue >= 1 && bucketValue < BUCKET_MAX_VALUE) {View on GitHub (pinned to 2add963021)
Solutions
- Null-check before calling delete() and skip null entries.
- Filter nulls out of the deletion candidate list before the loop.
- Fix the upstream nullable source of Keys.
Example fix
// before
for (Key k : expiredKeys) {
cbf.delete(k); // list contained a null
}
// throws NullPointerException: Key may not be null
// after
for (Key k : expiredKeys) {
if (k != null) {
cbf.delete(k);
}
} Defensive patterns
Strategy: validation
Validate before calling
for (Key k : expiredKeys) {
if (k != null) {
cbf.delete(k);
}
} Prevention
- Filter nulls from deletion candidate lists before the loop.
- Keep removal queues typed and non-null by construction.
- Log skipped nulls during maintenance sweeps for auditability.
When it happens
Trigger: cbf.delete(null); deleting keys from a nullable lookup result; maintenance jobs sweeping collections that contain null entries.
Common situations: Expiry/removal passes over caches where some entries were never populated; the null key arriving from deserialization or a cleared map slot.
Related errors
- key can not be null
- key cannot be null
- Key is not a member
- filters cannot be and-ed
- Value length unknown.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/d2a82f4376dcdeca.
Report an issue: GitHub.