apache/hadoop · error · HadoopIllegalArgumentException
!(element instanceof LinkedElement), element.getClass()=" +
Error message
!(element instanceof LinkedElement), element.getClass()=" + element.getClass()
What it means
Elements stored in LightWeightGSet must implement LinkedElement - the set chains hash collisions through the elements themselves instead of allocating wrapper nodes. put() catches the ClassCastException from the cast and rethrows HadoopIllegalArgumentException naming the element's actual class, telling you the type violates the GSet contract.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/LightWeightGSet.java:159
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++;
size++;
e.setNext(entries[index]);
entries[index] = e;
return existing;
}View on GitHub (pinned to 2add963021)
Solutions
- Make the element implement LinkedElement (getNext/setNext chaining), following existing element classes in the codebase.
- Type the reference as GSet<K, E extends LinkedElement> so misuse becomes a compile error.
- If the class cannot be modified, use a wrapper-based structure (java.util.HashSet) instead of GSet.
Example fix
// before
class MyEntry { // plain POJO
...
}
gset.put(myEntry); // HadoopIllegalArgumentException
// after
class MyEntry implements LightWeightGSet.LinkedElement {
private LinkedElement next;
@Override public LinkedElement getNext() { return next; }
@Override public void setNext(LinkedElement n) { next = n; }
}
gset.put(myEntry); Defensive patterns
Strategy: type-guard
Type guard
static <E> boolean isStorableInGSet(E element) {
return element != null && (element instanceof LinkedElement);
} Prevention
- Encode the contract in generics: declare GSet<K, E extends LinkedElement>.
- Copy getNext/setNext chaining from an existing GSet element class rather than inventing it.
When it happens
Trigger: put(element) where the element class does not implement LinkedElement: passing a plain POJO, or a subclass hierarchy from which the interface was dropped.
Common situations: Porting a custom cache to GSet; modifying inode-like classes in HDFS forks; test code inserting stand-in objects that implement only equals/hashCode.
Related errors
- FileSystem '{}'is not a ViewFileSystem.
- Input files cannot be merged as they have different Key and
- Input files cannot be merged as they have different Key clas
- key == null
- Null element is not supported.
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/ac1085374ba42087.
Report an issue: GitHub.