apache/hadoop · error · IllegalArgumentException
null argument passed in equal().
Error message
null argument passed in equal().
What it means
EnumSetWritable.equals() deliberately violates the standard equals contract by throwing IllegalArgumentException on a null argument instead of returning false. Any caller that follows the normal Java convention of comparing possibly-null references (HashMap lookups, Objects.equals expectations) will get an exception instead of false.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/EnumSetWritable.java:163
if (this.elementType == null)
throw new UnsupportedOperationException(
"Unable to serialize empty EnumSet with no element type provided.");
WritableUtils.writeString(out, this.elementType.getName());
}
for (int i = 0; i < length; i++) {
ObjectWritable.writeObject(out, array[i], array[i].getClass(), conf);
}
}
}
/**
* Returns true if <code>o</code> is an EnumSetWritable with the same value,
* or both are null.
*/
@Override
public boolean equals(Object o) {
if (o == null) {
throw new IllegalArgumentException("null argument passed in equal().");
}
if (!(o instanceof EnumSetWritable))
return false;
EnumSetWritable<?> other = (EnumSetWritable<?>) o;
if (this == o || (this.value == other.value))
return true;
if (this.value == null) // other.value must not be null if we reach here
return false;
return this.value.equals(other.value);
}
/**
* Returns the class of all the elements of the underlying EnumSetWriable. It
* may return null.View on GitHub (pinned to 2add963021)
Solutions
- Null-check before comparing: if (o != null && writable.equals(o)).
- Reverse the comparison when possible: pass the writable as the argument to a null-safe equals.
- Use java.util.Objects.equals carefully — it calls a.equals(b), so guard the EnumSetWritable side being non-null and the argument being non-null.
Example fix
// before boolean same = esw.equals(maybeNull); // throws when maybeNull == null // after boolean same = maybeNull != null && esw.equals(maybeNull);
Defensive patterns
Strategy: validation
Validate before calling
boolean same = (maybeNull instanceof EnumSetWritable) && esw.equals(maybeNull);
Type guard
static boolean safeEquals(EnumSetWritable<?> a, Object b) {
return b != null && a.equals(b);
} Prevention
- Null-check arguments before equals() — this class throws instead of returning false.
- Be careful with contains(null)/indexOf(null) on collections holding EnumSetWritable.
When it happens
Trigger: writable.equals(null); collections APIs that probe with null (e.g. list.contains(null), map.get-like scans); assertion libraries comparing against an expected null.
Common situations: Putting EnumSetWritable into ArrayList/HashSet and calling contains(null); comparing a decoded value to a null expected value in tests; generic pipeline code doing value.equals(current) where current may be null.
Related errors
- source map cannot be null
- null component type not allowed
- null value not allowed
- null valueClass
- The EnumSet argument is null, or is an empty set but with no
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/320289abd98ed1bb.
Report an issue: GitHub.