{"record":{"id":"f1461fcfedcbafb4","repo":"apache/hadoop","slug":"wrong-value-class-is-not","errorCode":null,"errorMessage":"wrong value class: {} is not {}","messagePattern":"wrong value class: (.+?) is not (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java","lineNumber":1476,"sourceCode":"    public void append(Writable key, Writable val)\n      throws IOException {\n      append((Object) key, (Object) val);\n    }\n\n    /**\n     * Append a key/value pair.\n     * @param key input Object key.\n     * @param val input Object val.\n     * @throws IOException raised on errors performing I/O.\n     */\n    @SuppressWarnings(\"unchecked\")\n    public synchronized void append(Object key, Object val)\n      throws IOException {\n      if (key.getClass() != keyClass)\n        throw new IOException(\"wrong key class: \"+key.getClass().getName()\n                              +\" is not \"+keyClass);\n      if (val.getClass() != valClass)\n        throw new IOException(\"wrong value class: \"+val.getClass().getName()\n                              +\" is not \"+valClass);\n\n      buffer.reset();\n\n      // Append the 'key'\n      keySerializer.serialize(key);\n      int keyLength = buffer.getLength();\n      if (keyLength < 0)\n        throw new IOException(\"negative length keys not allowed: \" + key);\n\n      // Append the 'value'\n      if (compress == CompressionType.RECORD) {\n        deflateFilter.resetState();\n        compressedValSerializer.serialize(val);\n        deflateOut.flush();\n        deflateFilter.finish();\n      } else {\n        uncompressedValSerializer.serialize(val);","sourceCodeStart":1458,"sourceCodeEnd":1494,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/SequenceFile.java#L1458-L1494","documentation":"The value-side twin of the key check in Writer.append: val.getClass() must be exactly (==) the declared valClass or append throws this IOException naming both classes. The check is per record, so a single bad value stops the write before the record header is emitted.","triggerScenarios":"Appending a value whose concrete class differs from Writer.valueClass(...): a subclass instance, a type from another library version, or null-ish placeholders with the wrong type after refactoring.","commonSituations":"Value schema changed in code but not in the writer options; mixed collections feeding append with heterogeneous elements; copy-paste writers reused across data types.","solutions":["Match Writer.valueClass(...) to the concrete appended type","Convert or copy subclass values into the exact declared type before append","Add a guard: val.getClass() == writer.getValueClass() before each append in generic plumbing"],"exampleFix":"// before\nWriter w = SequenceFile.createWriter(conf, Writer.file(p),\n    Writer.keyClass(Text.class), Writer.valueClass(IntWritable.class));\nw.append(new Text(\"k\"), new Text(\"not-an-int\")); // wrong value class\n\n// after\nw.append(new Text(\"k\"), new IntWritable(7));","handlingStrategy":"type-guard","validationCode":"if (val.getClass() != w.getValueClass()) {\n  throw new IllegalArgumentException(\"value \" + val.getClass() + \" != declared \" + w.getValueClass());\n}","typeGuard":"static boolean isExactValueClass(SequenceFile.Writer w, Object val) {\n  return val != null && val.getClass() == w.getValueClass();\n}","tryCatchPattern":"try {\n  w.append(key, val);\n} catch (IOException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"wrong value class\")) {\n    // value type drift: convert to the declared class or recreate the writer\n  } else { throw e; }\n}","preventionTips":["Derive Writer.valueClass(...) from the concrete type flowing through the pipeline, not a hand-typed literal","Subclasses are rejected too: materialize exact-class instances before append"],"tags":["hadoop","sequence-file","type-mismatch","append"],"backgroundTag":"key-value-class-mismatch","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}