apache/hadoop · error · NullPointerException
Null element is not supported.
Error message
Null element is not supported.
What it means
put(E) rejects null elements with NullPointerException("Null element is not supported."). The set chains elements itself through LinkedElement, so a null entry has no representation; the check at the top of put() is the cheapest place to catch the bug.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightGSet.java:153
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;
}
@Override
public E put(final E element) {
// validate element
if (element == null) {
throw new NullPointerException("Null element is not supported.");
}
LinkedElement e = null;
try {
e = (LinkedElement)element;
} catch (ClassCastException ex) {
throw new HadoopIllegalArgumentException(
"!(element instanceof LinkedElement), element.getClass()="
+ element.getClass());
}
// find index
final int index = getIndex(element);
// remove if it already exists
final E existing = remove(index, element);
// insert the element to the head of the linked list
modification++;View on GitHub (pinned to 2add963021)
Solutions
- Null-check the element between creation and insertion.
- Make 'absent' explicit at the creator (Optional or a not-found flag) instead of returning null.
- Use Objects.requireNonNull(element, "element from <source>") to fail with context.
Example fix
// before
gset.put(createEntry(id)); // createEntry returns null on failure
// after
E e = createEntry(id);
if (e != null) {
gset.put(e);
} Defensive patterns
Strategy: validation
Validate before calling
E element = factory.create(id);
if (element == null) {
// handle absence explicitly; do not insert
return;
}
gset.put(element); Prevention
- Do not insert factory results without a null check.
- Reserve null for 'absent' in lookups only, never for insert arguments.
When it happens
Trigger: Calling gset.put(null) - typically a create-then-insert flow where the factory or lookup returned null (not found, allocation failure) and the result was inserted unchecked.
Common situations: Cache fill code doing gset.put(load(x)) where load returns null on miss; refactoring that removed a null branch; tests inserting mock nulls.
Related errors
- key == null
- !(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/1b351249f28837bd.
Report an issue: GitHub.