{"record":{"id":"8577ecee04994678","repo":"apache/beam","slug":"unable-to-infer-a-coder-for-valuestate-and-no-coder-was","errorCode":null,"errorMessage":"Unable to infer a coder for ValueState and no Coder was specified. Please set a coder by either invoking StateSpecs.value(Coder<T> valueCoder) or by registering the coder in the Pipeline's CoderRegistry.","messagePattern":"Unable to infer a coder for ValueState and no Coder was specified\\. Please set a coder by either invoking StateSpecs\\.value\\(Coder<T> valueCoder\\) or by registering the coder in the Pipeline's CoderRegistry\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java","lineNumber":433,"sourceCode":"    }\n\n    @Override\n    public <ResultT> ResultT match(Cases<ResultT> cases) {\n      return cases.dispatchValue(coder);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void offerCoders(Coder[] coders) {\n      if (this.coder == null && coders[0] != null) {\n        this.coder = (Coder<T>) coders[0];\n      }\n    }\n\n    @Override\n    public void finishSpecifying() {\n      if (coder == null) {\n        throw new IllegalStateException(\n            \"Unable to infer a coder for ValueState and no Coder\"\n                + \" was specified. Please set a coder by either invoking\"\n                + \" StateSpecs.value(Coder<T> valueCoder) or by registering the coder in the\"\n                + \" Pipeline's CoderRegistry.\");\n      }\n    }\n\n    @Override\n    public boolean equals(@Nullable Object obj) {\n      if (obj == this) {\n        return true;\n      }\n\n      if (!(obj instanceof ValueStateSpec)) {\n        return false;\n      }\n\n      ValueStateSpec<?> that = (ValueStateSpec<?>) obj;","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L415-L451","documentation":"A ValueState spec created without an explicit coder (StateSpecs.value()) cannot infer how to serialize its values at pipeline-construction time. StateSpecs.ValueStateSpec.finishSpecifying() throws IllegalStateException when coder is still null after coder inference has run.","triggerScenarios":"Calling StateSpecs.value() with no Coder argument where the pipeline's CoderRegistry cannot infer a coder for the value type T (e.g. a custom POJO without a registered coder).","commonSituations":"Using a custom class as state value without registering a coder; using types not on the default coder registry; calling finishSpecifying outside a normal pipeline lifecycle where inference never ran.","solutions":["Pass an explicit coder: StateSpecs.value(myCoder).","Register the coder in the pipeline's CoderRegistry via pipeline.getCoderRegistry().registerCoderForType(...).","Make the value type use a codec/POJO type Beam can infer a coder for (e.g. Avro or annotated POJO)."],"exampleFix":"// before\nValueStateSpec<String> spec = StateSpecs.value();\n// after\nValueStateSpec<String> spec = StateSpecs.value(StringUtf8Coder.of());","handlingStrategy":"validation","validationCode":"if (valueCoder == null) {\n  Coder<T> inferred = pipeline.getCoderRegistry().getCoder(TypeDescriptor.of(T.class)); // must not throw\n}","typeGuard":null,"tryCatchPattern":"try {\n  StateSpecs.value(); // or pipeline.apply with state\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"Unable to infer a coder for ValueState\")) {\n    spec = StateSpecs.value(explicitCoder);\n  } else throw e;\n}","preventionTips":["Always pass an explicit coder to StateSpecs.value()","Register coders for custom types in the CoderRegistry at pipeline setup","Prefer Avro/annotated POJO types Beam can code automatically"],"tags":["java","apache-beam","state","coder-inference"],"backgroundTag":"missing-required-config","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"}