{"record":{"id":"fa2098e3e42246c0","repo":"apache/hadoop","slug":"map-cannot-be-copied","errorCode":null,"errorMessage":"map cannot be copied: {}","messagePattern":"map cannot be copied: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java","lineNumber":135,"sourceCode":"  protected byte getId(Class<?> clazz) {\n    return classToIdMap.containsKey(clazz) ? classToIdMap.get(clazz) : -1;\n  }\n\n  /**\n   * Used by child copy constructors.\n   * @param other other.\n   */\n  protected synchronized void copy(Writable other) {\n    if (other != null) {\n      try {\n        DataOutputBuffer out = new DataOutputBuffer();\n        other.write(out);\n        DataInputBuffer in = new DataInputBuffer();\n        in.reset(out.getData(), out.getLength());\n        readFields(in);\n\n      } catch (IOException e) {\n        throw new IllegalArgumentException(\"map cannot be copied: \" +\n            e.getMessage());\n      }\n\n    } else {\n      throw new IllegalArgumentException(\"source map cannot be null\");\n    }\n  }\n\n  /** constructor. */\n  protected AbstractMapWritable() {\n    this.conf = new AtomicReference<Configuration>();\n\n    addToMap(ArrayWritable.class, (byte)-127);\n    addToMap(BooleanWritable.class, (byte)-126);\n    addToMap(BytesWritable.class, (byte)-125);\n    addToMap(FloatWritable.class, (byte)-124);\n    addToMap(IntWritable.class, (byte)-123);\n    addToMap(LongWritable.class, (byte)-122);","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java#L117-L153","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy constructors fed maps produced by a different version of the subclass; entries whose classes are not visible to this map's registrations.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// verify the source serializes cleanly before copying\ntry {\n  DataOutputBuffer buf = new DataOutputBuffer();\n  other.write(buf);\n} catch (IOException e) {\n  throw new IllegalArgumentException(\"source map not serializable\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n  target.copyFrom(source);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"map cannot be copied\")) {\n    // the suffix is the original IOException message; fix that underlying issue\n  }\n}","preventionTips":["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"],"tags":["hadoop","serialization","writable","mapwritable","copy"],"backgroundTag":"writable-serialization-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}