apache/hadoop · error · IllegalArgumentException
The EnumSet argument is null, or is an empty set but with no
Error message
The EnumSet argument is null, or is an empty set but with no elementType provided.
What it means
EnumSetWritable wraps an EnumSet for serialization and must know the enum element type to write it. set(value, elementType) throws IllegalArgumentException when value is null or empty AND neither the elementType argument nor a previously stored elementType is available — there is no way to derive the enum class from an empty set.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/EnumSetWritable.java:97
*/
public EnumSetWritable(EnumSet<E> value) {
this(value, null);
}
/**
* reset the EnumSetWritable with specified
* <code>value</code> and <code>elementType</code>. If the <code>value</code> argument
* is null or its size is zero, the <code>elementType</code> argument must not be
* null. If the argument <code>value</code>'s size is bigger than zero, the
* argument <code>elementType</code> is not be used.
*
* @param value enumSet Value.
* @param elementType elementType.
*/
public void set(EnumSet<E> value, Class<E> elementType) {
if ((value == null || value.size() == 0)
&& (this.elementType == null && elementType == null)) {
throw new IllegalArgumentException(
"The EnumSet argument is null, or is an empty set but with no elementType provided.");
}
this.value = value;
if (value != null && value.size() > 0) {
Iterator<E> iterator = value.iterator();
this.elementType = iterator.next().getDeclaringClass();
} else if (elementType != null) {
this.elementType = elementType;
}
}
/**
* Return the value of this EnumSetWritable.
* @return EnumSet.
*/
public EnumSet<E> get() {
return value;
}View on GitHub (pinned to 2add963021)
Solutions
- Use the two-arg constructor for possibly-empty sets: new EnumSetWritable<>(value, MyEnum.class).
- When clearing, pass the type: set(null, MyEnum.class) or set(EnumSet.noneOf(MyEnum.class), MyEnum.class).
- Once an instance has held a non-empty set, elementType persists, so prefer populating a prototype with a real element or type at construction.
Example fix
// before EnumSetWritable<Flag> w = new EnumSetWritable<>(flags); // throws when flags is null/empty // after EnumSetWritable<Flag> w = new EnumSetWritable<>(flags, Flag.class);
Defensive patterns
Strategy: validation
Validate before calling
if ((value == null || value.isEmpty()) && elementType == null) {
throw new IllegalArgumentException("Empty EnumSet requires an element type");
}
new EnumSetWritable<>(value, elementType); Prevention
- Always use the two-arg constructor/set for possibly-empty enum sets.
- Pass the enum class explicitly when clearing fields: set(null, MyEnum.class).
When it happens
Trigger: new EnumSetWritable(null) (single-arg constructor delegates with null elementType); new EnumSetWritable(EnumSet.noneOf(Foo.class)); writable.set(null, null) after an instance that never learned a type.
Common situations: Wrapping optional enum-set fields that are legitimately empty; clearing a field with set(null, null) after constructing from an empty set; generic mapper code that always uses the one-arg constructor.
Related errors
- source map cannot be null
- null component type not allowed
- null value not allowed
- null valueClass
- Unable to serialize empty EnumSet with no element type provi
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/1c173b9f72fde223.
Report an issue: GitHub.