{"record":{"id":"faf72ae144f6eb8d","repo":"apache/hadoop","slug":"type-mismatch-in-value-from-map-expected-valuecl","errorCode":null,"errorMessage":"Type mismatch in value from map: expected {valueClassName}, received {actualValueClassName}","messagePattern":"Type mismatch in value from map: expected (.+?), received (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/MapTask.java","lineNumber":1102,"sourceCode":"            sortSpillException);\n      }\n    }\n\n    /**\n     * Serialize the key, value to intermediate storage.\n     * When this method returns, kvindex must refer to sufficient unused\n     * storage to store one METADATA.\n     */\n    public synchronized void collect(K key, V value, final int partition\n                                     ) throws IOException {\n      reporter.progress();\n      if (key.getClass() != keyClass) {\n        throw new IOException(\"Type mismatch in key from map: expected \"\n                              + keyClass.getName() + \", received \"\n                              + key.getClass().getName());\n      }\n      if (value.getClass() != valClass) {\n        throw new IOException(\"Type mismatch in value from map: expected \"\n                              + valClass.getName() + \", received \"\n                              + value.getClass().getName());\n      }\n      if (partition < 0 || partition >= partitions) {\n        throw new IOException(\"Illegal partition for \" + key + \" (\" +\n            partition + \")\");\n      }\n      checkSpillException();\n      bufferRemaining -= METASIZE;\n      if (bufferRemaining <= 0) {\n        // start spill if the thread is not running and the soft limit has been\n        // reached\n        spillLock.lock();\n        try {\n          do {\n            if (!spillInProgress) {\n              final int kvbidx = 4 * kvindex;\n              final int kvbend = 4 * kvend;","sourceCodeStart":1084,"sourceCodeEnd":1120,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapred/MapTask.java#L1084-L1120","documentation":"The sorting collector type-checks every value passed to OutputCollector.collect() / Context.write() with an exact getClass() comparison against the configured map-output value class (mapreduce.map.output.value.class, set via Job.setMapOutputValueClass). When map() emits a value whose runtime class - including a subclass - differs from the configured one, the map task fails with this IOException on the first offending record.","triggerScenarios":"Mapper emits value instances of a class different from job.getMapOutputValueClass(); setMapOutputValueClass never called so the final output value class is assumed; old-API JobConf with a wrong mapred.mapoutput.valueclass; emitting a subclass (e.g., a custom Writable extending Text).","commonSituations":"Mapper generic value parameter changed without updating the job; mapper writes IntWritable while only setOutputValueClass(Text.class) was set; combiner/reducer expectations drifting from the mapper; Avro/Pig-generated jobs with mis-set intermediate types.","solutions":["Call job.setMapOutputValueClass(...) with exactly the class map() writes (and setMapOutputKeyClass for the key)","Check the Mapper<K,V,K2,V2> generic signature and every context.write(...) site","Verify combiner input value types equal the map output value types","Run a one-record local integration test of the mapper before submitting"],"exampleFix":"// before\npublic class CountMapper extends Mapper<LongWritable, Text, Text, LongWritable> { /* writes LongWritable values */ }\njob.setOutputValueClass(Text.class);        // only final output classes set\n\n// after\njob.setMapOutputKeyClass(Text.class);\njob.setMapOutputValueClass(LongWritable.class);  // what the mapper emits\njob.setOutputKeyClass(Text.class);          // what the reducer emits\njob.setOutputValueClass(Text.class);","handlingStrategy":"validation","validationCode":"// before job.submit(): assert the exact value class the mapper emits\nClass<?> emitted = IntWritable.class; // class constructed at every context.write(...) in map()\nif (!job.getMapOutputValueClass().equals(emitted)) {\n  throw new IllegalStateException(\"Map output value class should be \" + emitted.getName()\n      + \", configured \" + job.getMapOutputValueClass().getName());\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set job.setMapOutputValueClass(...) explicitly in every job whose intermediate value type differs from the output type","Never emit subclasses of the declared Writable - getClass() is an exact match","Include a combiner round-trip test when intermediate types changed"],"tags":["hadoop","mapreduce","mapper","serialization","type-mismatch","configuration"],"backgroundTag":"serialization-type-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}