apache/hadoop · error · IllegalArgumentException
map cannot be copied: {}
Error message
map cannot be copied: {} What it means
AbstractMapWritable.copy(Writable) implements copying by serializing 'other' into a buffer and readFields-ing it back into 'this'. Any IOException from that write/read round-trip is rethrown as IllegalArgumentException('map cannot be copied: <io message>'). Note only the underlying message survives - the IOException's stack trace is dropped, which makes diagnosis harder.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java:135
protected byte getId(Class<?> clazz) {
return classToIdMap.containsKey(clazz) ? classToIdMap.get(clazz) : -1;
}
/**
* 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);View on GitHub (pinned to 2add963021)
Solutions
- Check the appended message text - it is the original IOException's message and usually names the real problem (often a class-not-registered or id conflict)
- Ensure source and target maps share the same registration table (same subclass/version on both sides)
- Test other.write(new DataOutputBuffer()) in isolation to identify the failing entry
Defensive patterns
Strategy: try-catch
Validate before calling
// verify the source serializes cleanly before copying
try {
DataOutputBuffer buf = new DataOutputBuffer();
other.write(buf);
} catch (IOException e) {
throw new IllegalArgumentException("source map not serializable", e);
} Try / catch
try {
target.copyFrom(source);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("map cannot be copied")) {
// the suffix is the original IOException message; fix that underlying issue
}
} Prevention
- Keep registration tables identical on both sides of a copy
- Unit-test write/read round-trips for every Writable you store
- Remember the original IOException stack trace is discarded - log the message early
When it happens
Trigger: new MapWritable(otherMap) or copyFrom(other) where an entry's write() fails: a value that is not Writable-serializable in this context, inconsistent registration tables between the two maps (see the class/id conflicts), or a value whose write throws.
Common situations: Copy constructors fed maps produced by a different version of the subclass; entries whose classes are not visible to this map's registrations.
Related errors
- Class {} already registered but maps to {} and not {}
- Id {} exists but maps to {} and not {}
- adding an additional class would exceed the maximum number a
- source map cannot be null
- Exception while get content summary
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/fa2098e3e42246c0.
Report an issue: GitHub.