{"record":{"id":"a43724f94800ab63","repo":"apache/beam","slug":"unable-to-deserialize-record-writablecoder","errorCode":null,"errorMessage":"unable to deserialize record","messagePattern":"unable to deserialize record","errorType":"exception","errorClass":"CoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-common/src/main/java/org/apache/beam/sdk/io/hadoop/WritableCoder.java","lineNumber":93,"sourceCode":"    value.write(new DataOutputStream(outStream));\n  }\n\n  @SuppressWarnings(\"unchecked\")\n  @Override\n  public T decode(InputStream inStream) throws IOException {\n    try {\n      if (type == NullWritable.class) {\n        // NullWritable has no default constructor\n        return (T) NullWritable.get();\n      }\n      T t = type.getDeclaredConstructor().newInstance();\n      t.readFields(new DataInputStream(inStream));\n      return t;\n    } catch (InstantiationException\n        | IllegalAccessException\n        | NoSuchMethodException\n        | InvocationTargetException e) {\n      throw new CoderException(\"unable to deserialize record\", e);\n    }\n  }\n\n  @Override\n  public List<Coder<?>> getCoderArguments() {\n    return Collections.emptyList();\n  }\n\n  @Override\n  public void verifyDeterministic() throws NonDeterministicException {\n    throw new NonDeterministicException(this, \"Hadoop Writable may be non-deterministic.\");\n  }\n\n  @Override\n  public boolean equals(@Nullable Object other) {\n    if (other == this) {\n      return true;\n    }","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-common/src/main/java/org/apache/beam/sdk/io/hadoop/WritableCoder.java#L75-L111","documentation":"WritableCoder decodes Hadoop Writable objects by reflectively instantiating the class and calling readFields. If instantiation or readFields fails via reflection, it throws this CoderException indicating the record could not be deserialized from the encoded stream.","triggerScenarios":"Decoding an encoded Writable (e.g. Text, IntWritable, custom Writable) when the class has no accessible no-arg constructor, the constructor throws, or readFields throws — often during pipeline deserialization of side inputs or grouped values.","commonSituations":"Custom Writable classes lacking a public no-arg constructor; class name changes between job submission and worker runtime; incompatible serialization format after upgrading Hadoop.","solutions":["Give the Writable class a public no-arg constructor","Ensure the Writable class is on the worker classpath and in the same package/name at encode and decode time","Keep Writable field format stable across versions, or bump a serialVersionUID-like version marker and migrate data","Read the wrapped reflective exception for the exact failure (constructor vs readFields)"],"exampleFix":"// before\nclass MyWritable implements Writable {\n  MyWritable(String s) { this.s = s; } // no no-arg ctor\n}\n// after\nclass MyWritable implements Writable {\n  public MyWritable() {}\n  MyWritable(String s) { this.s = s; }\n}","handlingStrategy":"try-catch","validationCode":"Class<? extends Writable> c = writableClass;\nc.getDeclaredConstructor().newInstance(); // fails fast if no accessible no-arg ctor","typeGuard":null,"tryCatchPattern":"try {\n  MyWritable w = coder.decode(stream, Coder.Context.OUTER);\n} catch (CoderException e) {\n  if (e.getMessage().contains(\"unable to deserialize record\")) {\n    LOGGER.severe(\"Writable decode failed: \" + e.getCause());\n  }\n  throw e;\n}","preventionTips":["Always provide a public no-arg constructor on custom Writables","Keep Writable class names/packages stable across deploy versions","Avoid changing Writable field formats without a migration plan"],"tags":["java","hadoop","writable","serialization","coder"],"backgroundTag":"deserialization-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}