apache/hadoop · error · NullPointerException
Collection<Key> can not be null
Error message
Collection<Key> can not be null
What it means
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.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java:158
if (key == null) {
throw new NullPointerException("key can not be null");
}
int[] h = hash.hash(key);
hash.clear();
for (int i = 0; i < nbHash; i++) {
fpVector[h[i]].add(key);
}
}
/**
* Adds a collection of false positive information to <i>this</i> retouched Bloom filter.
* @param coll The collection of false positive.
*/
public void addFalsePositive(Collection<Key> coll) {
if (coll == null) {
throw new NullPointerException("Collection<Key> can not be null");
}
for (Key k : coll) {
addFalsePositive(k);
}
}
/**
* Adds a list of false positive information to <i>this</i> retouched Bloom filter.
* @param keys The list of false positive.
*/
public void addFalsePositive(List<Key> keys) {
if (keys == null) {
throw new NullPointerException("ArrayList<Key> can not be null");
}
for (Key k : keys) {
addFalsePositive(k);View on GitHub (pinned to 2add963021)
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
Example fix
// before rbf.addFalsePositive(coll); // NPE when coll == null // after rbf.addFalsePositive(coll != null ? coll : Collections.<Key>emptyList());
Defensive patterns
Strategy: validation
Validate before calling
rbf.addFalsePositive(coll != null ? coll : Collections.<Key>emptyList());
Prevention
- 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
When it happens
Trigger: rbf.addFalsePositive((Collection<Key>) null); passing a never-initialized field; a method parameter that an upstream branch left null.
Common situations: Optional feedback stages that skip building the collection and pass null; fields initialized only inside a conditional; glue code mapping 'absent' to null.
Related errors
- ArrayList<Key> can not be null
- value can not be null
- key can not be null
- Key[] can not be null
- Key can not be null
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/8b8c4e0c42d5161d.
Report an issue: GitHub.