{"record":{"id":"b2a49631ecdf0c36","repo":"apache/beam","slug":"cannot-find-coder-for-s","errorCode":null,"errorMessage":"Cannot find coder for %s  : ","messagePattern":"Cannot find coder for (.+?)  : ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java","lineNumber":606,"sourceCode":"            String.format(errorMsg, getinputFormatClass().getRawType(), inputType.getRawType()));\n      }\n    }\n\n    /**\n     * Returns the default coder for a given type descriptor. Coder Registry is queried for correct\n     * coder, if not found in Coder Registry, then check if the type descriptor provided is of type\n     * Writable, then WritableCoder is returned, else exception is thrown \"Cannot find coder\".\n     */\n    @SuppressWarnings({\"unchecked\", \"WeakerAccess\"})\n    public <T> Coder<T> getDefaultCoder(TypeDescriptor<?> typeDesc, CoderRegistry coderRegistry) {\n      Class classType = typeDesc.getRawType();\n      try {\n        return (Coder<T>) coderRegistry.getCoder(typeDesc);\n      } catch (CannotProvideCoderException e) {\n        if (Writable.class.isAssignableFrom(classType)) {\n          return (Coder<T>) WritableCoder.of(classType);\n        }\n        throw new IllegalStateException(\n            String.format(\"Cannot find coder for %s  : \", typeDesc) + e.getMessage(), e);\n      }\n    }\n  }\n\n  /**\n   * Bounded source implementation for {@link HadoopFormatIO}.\n   *\n   * @param <K> Type of keys to be read.\n   * @param <V> Type of values to be read.\n   */\n  public static class HadoopInputFormatBoundedSource<K, V> extends BoundedSource<KV<K, V>>\n      implements Serializable {\n    private final SerializableConfiguration conf;\n    private final Coder<K> keyCoder;\n    private final Coder<V> valueCoder;\n    private final @Nullable SimpleFunction<?, K> keyTranslationFunction;\n    private final @Nullable SimpleFunction<?, V> valueTranslationFunction;","sourceCodeStart":588,"sourceCodeEnd":624,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/hadoop-format/src/main/java/org/apache/beam/sdk/io/hadoop/format/HadoopFormatIO.java#L588-L624","documentation":"HadoopFormatIO.getDefaultCoder() throws IllegalStateException(\"Cannot find coder for %s : \") when the CoderRegistry cannot provide a coder for the InputFormat's key or value type and the type is not a Hadoop Writable. Beam must be able to serialize these types to distribute read results.","triggerScenarios":"Expanding a HadoopFormatIO.Read where the configured key class or value class is neither registry-codable (e.g. a custom POJO without registered coder) nor implements org.apache.hadoop.io.Writable.","commonSituations":"Custom InputFormat returning plain Java objects or third-party types; using types like java.net.URI or custom Thrift/Protobuf classes without registering coders; missing avro/writable conversions.","solutions":["Make the key/value classes implement Writable, so WritableCoder is used automatically.","Register a coder for the type in the CoderRegistry before expanding: coderRegistry.registerCoderForClass(MyType.class, new MyTypeCoder()).","Set a coder explicitly on the transformed PCollection with setCoder(...) after mapping to a codable type.","Translate key/value to standard codable types (String, Long, Avro records) via withKeyTranslation/withValueTranslation."],"exampleFix":"// before\nconf.setClass(\"key.class\", MyCustomKey.class, Object.class); // not Writable, no coder\n// after\npublic class MyCustomKey implements Writable { ... }","handlingStrategy":"validation","validationCode":"Class<?> kv = conf.getClass(\"key.class\", null);\nif (!Writable.class.isAssignableFrom(kv)) { coderRegistry.registerCoderForClass(kv, myCustomCoder); }","typeGuard":"boolean hasCoder(CoderRegistry r, Class<?> c) { try { r.getCoder(c); return true; } catch (CannotProvideCoderException e) { return Writable.class.isAssignableFrom(c); } }","tryCatchPattern":"try { pipeline.apply(read); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Cannot find coder for\")) { registerCoderFor(conf key/value classes); } throw e; }","preventionTips":["Prefer Writable key/value classes in InputFormats used with Beam","Register custom coders before expansion","Test pipeline construction (expand) in unit tests to catch coder gaps early"],"tags":["java","beam","coder","serialization"],"backgroundTag":"class-not-found","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"}