apache/hadoop · error · IllegalArgumentException

null valueClass

Error message

null valueClass

What it means

ArrayWritable stores an array of Writable instances all of a single value class, which it needs at read time to instantiate elements via ReflectionUtils. The constructor rejects a null valueClass immediately with IllegalArgumentException because deserialization would otherwise be impossible.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/ArrayWritable.java:52

 *
 * For example:
 * <code>
 * public class IntArrayWritable extends ArrayWritable {
 *   public IntArrayWritable() { 
 *     super(IntWritable.class); 
 *   }	
 * }
 * </code>
 */
@InterfaceAudience.Public
@InterfaceStability.Stable
public class ArrayWritable implements Writable {
  private final Class<? extends Writable> valueClass;
  private Writable[] values;

  public ArrayWritable(Class<? extends Writable> valueClass) {
    if (valueClass == null) { 
      throw new IllegalArgumentException("null valueClass"); 
    }    
    this.valueClass = valueClass;
  }

  public ArrayWritable(Class<? extends Writable> valueClass, Writable[] values) {
    this(valueClass);
    this.values = values;
  }

  public ArrayWritable(String[] strings) {
    this(Text.class, new Writable[strings.length]);
    for (int i = 0; i < strings.length; i++) {
      values[i] = new UTF8(strings[i]);
    }
  }

  public Class<? extends Writable> getValueClass() {
    return valueClass;

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass the concrete Writable element class, e.g. new ArrayWritable(Text.class).
  2. Null-check any dynamically resolved class and fail loudly at configuration time with the class name that failed to resolve.
  3. For string arrays, the convenience constructor new ArrayWritable(String[]) exists.

Example fix

// before
Class<? extends Writable> vc = resolve(name); // null on failure
new ArrayWritable(vc);

// after
Class<? extends Writable> vc = resolve(name);
if (vc == null) throw new IllegalArgumentException("Cannot resolve element class " + name);
new ArrayWritable(vc);
Defensive patterns

Strategy: validation

Validate before calling

Class<? extends Writable> vc = resolveValueClass(schema);
if (vc == null) throw new IllegalArgumentException("Element class not resolvable for " + schema);
ArrayWritable aw = new ArrayWritable(vc);

Prevention

When it happens

Trigger: new ArrayWritable(null) or new ArrayWritable(null, values); typically the class constant was computed and came back null (e.g. Class.forName wrapped in a try/catch that defaults to null).

Common situations: Building ArrayWritable dynamically per schema/config where the element class lookup fails silently; copy-pasted code omitting the class argument's import so a null variable is passed.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/daf73c8803e71039. Report an issue: GitHub.