apache/hadoop · error · IllegalArgumentException

source map cannot be null

Error message

source map cannot be null

What it means

The copy method explicitly rejects a null source: passing null Writable to AbstractMapWritable.copy (via copy constructors like MapWritable(MapWritable) or SortedMapWritable(SortedMapWritable), or a manual copyFrom(null)) throws IllegalArgumentException('source map cannot be null'). It is a simple precondition guard before any serialization happens.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java:140

   * Used by child copy constructors.
   * @param other other.
   */
  protected synchronized void copy(Writable other) {
    if (other != null) {
      try {
        DataOutputBuffer out = new DataOutputBuffer();
        other.write(out);
        DataInputBuffer in = new DataInputBuffer();
        in.reset(out.getData(), out.getLength());
        readFields(in);

      } catch (IOException e) {
        throw new IllegalArgumentException("map cannot be copied: " +
            e.getMessage());
      }

    } else {
      throw new IllegalArgumentException("source map cannot be null");
    }
  }

  /** constructor. */
  protected AbstractMapWritable() {
    this.conf = new AtomicReference<Configuration>();

    addToMap(ArrayWritable.class, (byte)-127);
    addToMap(BooleanWritable.class, (byte)-126);
    addToMap(BytesWritable.class, (byte)-125);
    addToMap(FloatWritable.class, (byte)-124);
    addToMap(IntWritable.class, (byte)-123);
    addToMap(LongWritable.class, (byte)-122);
    addToMap(MapWritable.class, (byte)-121);
    addToMap(MD5Hash.class, (byte)-120);
    addToMap(NullWritable.class, (byte)-119);
    addToMap(ObjectWritable.class, (byte)-118);
    addToMap(SortedMapWritable.class, (byte)-117);

View on GitHub (pinned to 2add963021)

Solutions

  1. Guard the call site: only copy when the source is non-null, or pass a fresh empty map for the absent case
  2. Use Objects.requireNonNull(source, ...) at your own API boundary to fail with a clearer message

Example fix

// before
MapWritable copy = new MapWritable(maybeNull);

// after
MapWritable copy = (maybeNull != null)
    ? new MapWritable(maybeNull)
    : new MapWritable();
Defensive patterns

Strategy: validation

Validate before calling

MapWritable copy = (source != null)
    ? new MapWritable(source)
    : new MapWritable();
// or: Objects.requireNonNull(source, "source map");

Prevention

When it happens

Trigger: MapWritable copy constructor invoked with a null argument, typically from code that fetched a map from a context where it may legitimately be absent (cache miss, absent job conf entry).

Common situations: Optional accumulator patterns where 'no previous value' is represented as null and then passed to a copy constructor.

Related errors


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