apache/hadoop · error · NullPointerException
key == null
Error message
key == null
What it means
LightWeightGSet, Hadoop's chained hash set behind hot structures like the NameNode INode map, has no null-key semantics: get(K) throws NullPointerException("key == null") before any hashing. The explicit check fails fast with a searchable message instead of an opaque NPE from inside the hashing logic.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightGSet.java:130
public int size() {
return size;
}
protected int getIndex(final K key) {
return key.hashCode() & hash_mask;
}
protected E convert(final LinkedElement e){
@SuppressWarnings("unchecked")
final E r = (E)e;
return r;
}
@Override
public E get(final K key) {
//validate key
if (key == null) {
throw new NullPointerException("key == null");
}
//find element
final int index = getIndex(key);
for(LinkedElement e = entries[index]; e != null; e = e.getNext()) {
if (e.equals(key)) {
return convert(e);
}
}
//element not found
return null;
}
@Override
public boolean contains(final K key) {
return get(key) != null;
}
View on GitHub (pinned to 2add963021)
Solutions
- Use the stack trace to find the caller passing null and null-check the identifier at its source.
- Give null a real meaning at the boundary: skip the lookup or throw a descriptive domain exception.
- Never store or query null keys in GSet-based structures.
Example fix
// before INode node = inodes.get(pathComponent); // pathComponent may be null // after INode node = (pathComponent != null) ? inodes.get(pathComponent) : null;
Defensive patterns
Strategy: validation
Validate before calling
if (key == null) {
return null; // or throw a domain exception describing the missing identifier
}
return gset.get(key); Prevention
- Validate identifiers at the parse/lookup boundary so null never reaches the data structure.
- Prefer Objects.requireNonNull(x, "name") at assignment sites to fail with context.
When it happens
Trigger: Calling gset.get(null) - a null identifier (inode name, block id) propagated from a failed parse or an upstream lookup that returned null.
Common situations: Refactors that made an identifier optional; a lookup-by-name where the name was never validated; code assuming the set tolerates null keys like java.util.HashMap.
Related errors
- Null element is not supported.
- !(element instanceof LinkedElement), element.getClass()=" +
- modification=" + modification + " != iterModification = " +
- There are no more elements
- There is no current element to remove
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/4e622ed28537f630.
Report an issue: GitHub.