{"record":{"id":"2cbb548d72ef02d5","repo":"apache/beam","slug":"cannot-provide-coder-for-elements-of-create-for-their-common-2cbb54","errorCode":null,"errorMessage":"Cannot provide coder for elements of Create: For their common class, no coder could be provided. Based on their values, no coder could be inferred.","messagePattern":"Cannot provide coder for elements of Create: For their common class, no coder could be provided\\. Based on their values, no coder could be inferred\\.","errorType":"exception","errorClass":"CannotProvideCoderException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Create.java","lineNumber":1008,"sourceCode":"    Optional<Coder<?>> coder = Optional.absent();\n    for (Object elem : elems) {\n      Coder<?> c = inferCoderFromObject(coderRegistry, schemaRegistry, elem);\n      if (!coder.isPresent()) {\n        coder = (Optional) Optional.of(c);\n      } else if (!Objects.equals(c, coder.get())) {\n        throw new CannotProvideCoderException(\n            \"Cannot provide coder for elements of \"\n                + Create.class.getSimpleName()\n                + \":\"\n                + \" For their common class, no coder could be provided.\"\n                + \" Based on their values, they do not all default to the same Coder.\");\n      }\n    }\n    if (coder.isPresent()) {\n      return coder.get();\n    }\n\n    throw new CannotProvideCoderException(\n        \"Cannot provide coder for elements of \"\n            + Create.class.getSimpleName()\n            + \":\"\n            + \" For their common class, no coder could be provided.\"\n            + \" Based on their values, no coder could be inferred.\");\n  }\n\n  /**\n   * Attempt to infer the type for some very common Apache Beam parameterized types.\n   *\n   * <p>TODO: Instead, build a TypeDescriptor so that the {@link CoderRegistry} is invoked for the\n   * type instead of hard coding the coders for common types.\n   */\n  private static Coder<?> inferCoderFromObject(\n      CoderRegistry coderRegistry, SchemaRegistry schemaRegistry, Object o)\n      throws CannotProvideCoderException {\n\n    if (o == null) {","sourceCodeStart":990,"sourceCodeEnd":1026,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Create.java#L990-L1026","documentation":"Create.of(...) failed to infer any Coder at all: every call to inferCoderFromObject returned a coder but none was kept, or no coder could be inferred for the element values, so after the loop coder is empty and CannotProvideCoderException is thrown. Beam requires a deterministic way to serialize PCollection elements and refuses to guess.","triggerScenarios":"Calling Create.of(single element or all elements) where inferCoderFromObject throws/cannot resolve a coder for the element's class — e.g. a plain class with no DefaultCoder, no coder registered in CoderRegistry, and not a known simple/Serializable type.","commonSituations":"Custom domain classes used with Create.of without @DefaultCoder; classes added in a refactor that lost their coder registration; running under a test harness where CoderRegistry customizations were not applied.","solutions":["Provide the coder explicitly with .withCoder(...) on the Create transform","Annotate the element class with @DefaultCoder(AvroCoder.class) (or your coder)","Register the coder: pipeline.getCoderRegistry().registerCoderForClass(MyType.class, MyTypeCoder.of())","Verify the element type is one Beam can infer (primitive, Serializable, Pojo/Row/Proto with schema providers enabled)"],"exampleFix":"// before\npipeline.apply(Create.of(new MyRecord()))\n// after\npipeline.apply(Create.of(new MyRecord()).withCoder(AvroCoder.of(MyRecord.class)))","handlingStrategy":"validation","validationCode":"try {\n  pipeline.getCoderRegistry().getCoder(MyRecord.class);\n} catch (CannotProvideCoderException e) {\n  pipeline.getCoderRegistry().registerCoderForClass(MyRecord.class, AvroCoder.of(MyRecord.class));\n}","typeGuard":null,"tryCatchPattern":"try {\n  pipeline.apply(Create.of(elems));\n} catch (CannotProvideCoderException e) {\n  pipeline.apply(Create.of(elems).withCoder(AvroCoder.of(MyRecord.class)));\n}","preventionTips":["Always give custom classes an @DefaultCoder or explicit withCoder","Check element types are schema/Serializable supported before building Create transforms"],"tags":["apache-beam","java","coder-inference","pipeline-construction"],"backgroundTag":"type-mismatch","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}