{"record":{"id":"33572904bec84b67","repo":"apache/beam","slug":"unable-to-infer-a-coder-and-no-coder-was-specified-please","errorCode":null,"errorMessage":"Unable to infer a coder and no Coder was specified. Please set a coder by invoking Create.withCoder() explicitly  or a schema by invoking Create.withSchema().","messagePattern":"Unable to infer a coder and no Coder was specified\\. Please set a coder by invoking Create\\.withCoder\\(\\) explicitly  or a schema by invoking Create\\.withSchema\\(\\)\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Create.java","lineNumber":397,"sourceCode":"            try {\n              coder =\n                  SchemaCoder.of(\n                      schemaRegistry.getSchema(typeDescriptor.get()),\n                      typeDescriptor.get(),\n                      schemaRegistry.getToRowFunction(typeDescriptor.get()),\n                      schemaRegistry.getFromRowFunction(typeDescriptor.get()));\n            } catch (NoSuchSchemaException e) {\n              // No schema registered.\n            }\n            if (coder == null) {\n              coder = coderRegistry.getCoder(typeDescriptor.get());\n            }\n          } else {\n            coder = getDefaultCreateCoder(coderRegistry, schemaRegistry, elems);\n          }\n        }\n      } catch (CannotProvideCoderException e) {\n        throw new IllegalArgumentException(\n            \"Unable to infer a coder and no Coder was specified. \"\n                + \"Please set a coder by invoking Create.withCoder() explicitly \"\n                + \" or a schema by invoking Create.withSchema().\",\n            e);\n      }\n      try {\n        if (!alwaysUseRead) {\n          int numElements = Iterables.size(elems);\n          if (numElements == 0) {\n            return input\n                .apply(Impulse.create())\n                .apply(\n                    FlatMapElements.via(\n                        new SimpleFunction<byte[], Iterable<T>>() {\n                          @Override\n                          public Iterable<T> apply(byte[] input) {\n                            return Collections.emptyList();\n                          }","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Create.java#L379-L415","documentation":"Create<T> needs a Coder for its elements. When no coder was supplied via withCoder() and no schema via withSchema(), Beam tries to infer one from the element classes; if inference fails with CannotProvideCoderException, expand() wraps the failure in this IllegalArgumentException. The library throws because a PCollection cannot exist without a coder.","triggerScenarios":"Calling Create.of(elems) where elements' runtime class has no registered/default coder (e.g. a POJO without schema inference support, an interface type, or Object), and neither withCoder() nor withSchema() was called.","commonSituations":"Create.of(someListOfCustomPojo) before registering a schema; Create.of(mixedTypeList) inferred as Object; using types like java.lang.Object or generic type-erased collections in tests or quick prototypes.","solutions":["Add .withCoder(MyCoder.of()) to the Create transform with an explicit coder for T.","Alternatively call .withSchema(...) if T is a schema-annotated POJO/bean.","Register a default coder via CoderRegistry.registerCoderForClass(MyPojo.class, MyPojoCoder.class) on the pipeline.","If T is a schema class, annotate it with @DefaultSchema or implement Serializable and use a SerializableCoder."],"exampleFix":"// before\np.apply(Create.of(myPojoList)); // CannotProvideCoderException for MyPojo\n// after\np.apply(Create.of(myPojoList).withCoder(SerializableCoder.of(MyPojo.class)));","handlingStrategy":"validation","validationCode":"try { pipeline.getCoderRegistry().getCoder(javaType); } catch (CannotProvideCoderException e) { /* supply withCoder/withSchema */ }","typeGuard":"boolean canInferCoder(Pipeline p, Class<?> t) { try { p.getCoderRegistry().getCoder(TypeDescriptor.of(t)); return true; } catch (CannotProvideCoderException e) { return false; } }","tryCatchPattern":"try { p.apply(Create.of(elems)); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Unable to infer a coder\")) { p.apply(Create.of(elems).withCoder(SerializableCoder.of(MyType.class))); } else throw e; }","preventionTips":["Habitually chain .withCoder(...) for non-trivial element types","Register default coders for domain POJOs at pipeline setup","Use schema-annotated classes so withSchema/inference works"],"tags":["java","apache-beam","create","coder-inference"],"backgroundTag":"missing-required-argument","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"}