{"record":{"id":"6457f5100787c470","repo":"apache/hadoop","slug":"source-map-cannot-be-null","errorCode":null,"errorMessage":"source map cannot be null","messagePattern":"source map cannot be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java","lineNumber":140,"sourceCode":"   * 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);\n    addToMap(MapWritable.class, (byte)-121);\n    addToMap(MD5Hash.class, (byte)-120);\n    addToMap(NullWritable.class, (byte)-119);\n    addToMap(ObjectWritable.class, (byte)-118);\n    addToMap(SortedMapWritable.class, (byte)-117);","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/AbstractMapWritable.java#L122-L158","documentation":"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.","triggerScenarios":"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).","commonSituations":"Optional accumulator patterns where 'no previous value' is represented as null and then passed to a copy constructor.","solutions":["Guard the call site: only copy when the source is non-null, or pass a fresh empty map for the absent case","Use Objects.requireNonNull(source, ...) at your own API boundary to fail with a clearer message"],"exampleFix":"// before\nMapWritable copy = new MapWritable(maybeNull);\n\n// after\nMapWritable copy = (maybeNull != null)\n    ? new MapWritable(maybeNull)\n    : new MapWritable();","handlingStrategy":"validation","validationCode":"MapWritable copy = (source != null)\n    ? new MapWritable(source)\n    : new MapWritable();\n// or: Objects.requireNonNull(source, \"source map\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Null-check optional sources before copy constructors","Represent 'absent' as an empty map at your API boundary instead of null"],"tags":["hadoop","serialization","writable","null-check","mapwritable"],"backgroundTag":"null-argument-rejected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}