{"record":{"id":"9897aa674392e51f","repo":"apache/beam","slug":"unable-to-infer-a-coder-for-setstate-and-no-coder-was","errorCode":null,"errorMessage":"Unable to infer a coder for SetState and no Coder was specified. Please set a coder by either invoking StateSpecs.set(Coder<T> elemCoder) or by registering the coder in the Pipeline's CoderRegistry.","messagePattern":"Unable to infer a coder for SetState and no Coder was specified\\. Please set a coder by either invoking StateSpecs\\.set\\(Coder<T> elemCoder\\) 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":893,"sourceCode":"    }\n\n    @Override\n    public <ResultT> ResultT match(Cases<ResultT> cases) {\n      return cases.dispatchSet(elemCoder);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void offerCoders(Coder[] coders) {\n      if (this.elemCoder == null && coders[0] != null) {\n        this.elemCoder = (Coder<T>) coders[0];\n      }\n    }\n\n    @Override\n    public void finishSpecifying() {\n      if (elemCoder == null) {\n        throw new IllegalStateException(\n            \"Unable to infer a coder for SetState and no Coder\"\n                + \" was specified. Please set a coder by either invoking\"\n                + \" StateSpecs.set(Coder<T> elemCoder) 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 SetStateSpec)) {\n        return false;\n      }\n\n      SetStateSpec<?> that = (SetStateSpec<?>) obj;","sourceCodeStart":875,"sourceCodeEnd":911,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L875-L911","documentation":"finishSpecifying on the SetState spec found elemCoder null: StateSpecs.set(...) was called without a coder and CoderRegistry inference failed to offer one before specification finished. The set's element type is the input at fault; the message prescribes the two remedies (pass a coder explicitly or register one).","triggerScenarios":"Calling StateSpecs.set() (no-arg overload) where the element type T's coder cannot be inferred by the CoderRegistry.","commonSituations":"Sets of custom POJOs or third-party types without registered coders; building state specs in tests outside normal pipeline coder inference.","solutions":["Pass an explicit element coder: StateSpecs.set(elemCoder).","Register a coder for T in the pipeline's CoderRegistry.","Use an element type with a default/inferrable coder."],"exampleFix":"// before\nSetStateSpec<String> spec = StateSpecs.set();\n// after\nSetStateSpec<String> spec = StateSpecs.set(StringUtf8Coder.of());","handlingStrategy":"validation","validationCode":"if (elemCoder == null) {\n  throw new IllegalStateException(\"Supply StateSpecs.set(elemCoder) with an explicit element coder\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = StateSpecs.set();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"SetState\")) {\n    spec = StateSpecs.set(elemCoder);\n  } else throw e;\n}","preventionTips":["Always pass an explicit element coder to StateSpecs.set()","Register coders for custom element types","Validate pipeline construction in tests so coder inference gaps surface early"],"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-20T03:17:13.778Z"}