{"record":{"id":"bc0cebdf153d05bd","repo":"apache/beam","slug":"cannot-provide-s-because-s-does-not-implement-the-interface","errorCode":null,"errorMessage":"Cannot provide %s because %s does not implement the interface %s","messagePattern":"Cannot provide (.+?) because (.+?) does not implement the interface (.+?)","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-common/src/main/java/org/apache/beam/sdk/io/hadoop/WritableCoder.java","lineNumber":157,"sourceCode":"  @AutoService(CoderProviderRegistrar.class)\n  public static class WritableCoderProviderRegistrar implements CoderProviderRegistrar {\n\n    @Override\n    public List<CoderProvider> getCoderProviders() {\n      return Collections.singletonList(getCoderProvider());\n    }\n  }\n\n  /** A {@link CoderProvider} for Hadoop {@link Writable writable types}. */\n  private static class WritableCoderProvider extends CoderProvider {\n    private static final TypeDescriptor<Writable> WRITABLE_TYPE = new TypeDescriptor<Writable>() {};\n\n    @Override\n    public <T> Coder<T> coderFor(\n        TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders)\n        throws CannotProvideCoderException {\n      if (!typeDescriptor.isSubtypeOf(WRITABLE_TYPE)) {\n        throw new CannotProvideCoderException(\n            String.format(\n                \"Cannot provide %s because %s does not implement the interface %s\",\n                WritableCoder.class.getSimpleName(), typeDescriptor, Writable.class.getName()));\n      }\n\n      try {\n        @SuppressWarnings(\"unchecked\")\n        Coder<T> coder = WritableCoder.of((Class) typeDescriptor.getRawType());\n        return coder;\n      } catch (IllegalArgumentException e) {\n        throw new CannotProvideCoderException(e);\n      }\n    }\n  }\n}\n","sourceCodeStart":139,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-common/src/main/java/org/apache/beam/sdk/io/hadoop/WritableCoder.java#L139-L173","documentation":"WritableCoder.coderFor() refuses to supply a Coder when the requested TypeDescriptor does not implement org.apache.hadoop.io.Writable. The Beam Hadoop IO layer only knows how to serialize Hadoop Writable types, so it throws CannotProvideCoderException to let the pipeline fall back to another CoderProvider.","triggerScenarios":"Using WritableCoder's coderFor() with a TypeDescriptor whose raw type does not implement Writable, e.g. asking for a coder for a plain POJO or java.lang.String through the Hadoop coder provider.","commonSituations":"Developers building Beam pipelines over HDFS inputs whose record class is a custom POJO that never implemented WritableComparable, or after refactoring a class to drop the Writable interface.","solutions":["Make the record class implement org.apache.hadoop.io.Writable (or WritableComparable) with write()/readFields().","Register or specify an explicit Coder for the type instead of relying on the Hadoop coder provider.","Wrap the data in an existing Writable type such as Text, IntWritable, or BytesWritable."],"exampleFix":"// before\nclass MyRecord { String id; }\n// after\nclass MyRecord implements Writable {\n  String id;\n  public void write(DataOutput out) throws IOException { out.writeUTF(id); }\n  public void readFields(DataInput in) throws IOException { id = in.readUTF(); }\n}","handlingStrategy":"validation","validationCode":"if (!org.apache.hadoop.io.Writable.class.isAssignableFrom(MyRecord.class)) {\n  throw new IllegalArgumentException(\"MyRecord must implement Writable\");\n}","typeGuard":"static <T> boolean isWritable(Class<T> cls) { return Writable.class.isAssignableFrom(cls); }","tryCatchPattern":"try {\n  coder = coderProvider.coderFor(typeDesc, comps);\n} catch (CannotProvideCoderException e) {\n  coder = fallbackCoder; // e.g. SerializableCoder.of(typeDesc)\n}","preventionTips":["Always implement Writable/WritableComparable for HDFS record types","Prefer built-in Writables (Text, IntWritable) for simple values","Register explicit Coders for custom types in the pipeline"],"tags":["java","serialization","hadoop","beam"],"backgroundTag":"incompatible-source-type","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"}