{"record":{"id":"4c22d257e55c59d4","repo":"apache/beam","slug":"unable-to-infer-a-coder-for-combiningstate-and-no-coder-was","errorCode":null,"errorMessage":"Unable to infer a coder for CombiningState and no Coder was specified. Please set a coder by either invoking StateSpecs.combining(Coder<AccumT> accumCoder, CombineFn<InputT, AccumT, OutputT> combineFn) or by registering the coder in the Pipeline's CoderRegistry.","messagePattern":"Unable to infer a coder for CombiningState and no Coder was specified\\. Please set a coder by either invoking StateSpecs\\.combining\\(Coder<AccumT> accumCoder, CombineFn<InputT, AccumT, OutputT> combineFn\\) 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":499,"sourceCode":"    }\n\n    @Override\n    public <ResultT> ResultT match(Cases<ResultT> cases) {\n      return cases.dispatchCombining(combineFn, accumCoder);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void offerCoders(Coder[] coders) {\n      if (this.accumCoder == null && coders[1] != null) {\n        this.accumCoder = (Coder<AccumT>) coders[1];\n      }\n    }\n\n    @Override\n    public void finishSpecifying() {\n      if (accumCoder == null) {\n        throw new IllegalStateException(\n            \"Unable to infer a coder for\"\n                + \" CombiningState and no Coder was specified.\"\n                + \" Please set a coder by either invoking\"\n                + \" StateSpecs.combining(Coder<AccumT> accumCoder,\"\n                + \" CombineFn<InputT, AccumT, OutputT> combineFn)\"\n                + \" or by registering the coder in the 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 CombiningStateSpec)) {\n        return false;\n      }","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L481-L517","documentation":"A CombiningState spec created via StateSpecs.combining(combineFn) without an accumulator coder cannot infer one at finishSpecifying time. StateSpecs.CombiningStateSpec.finishSpecifying() throws IllegalStateException when accumCoder is null.","triggerScenarios":"Calling StateSpecs.combining(CombineFn) (the overload without a Coder<AccumT>) where coder inference for the accumulator type AccumT fails.","commonSituations":"Custom CombineFn whose accumulator type is a custom class with no registered coder; using combining state with non-trivial accumulator types in pipelines without explicit coder registration.","solutions":["Use the two-argument factory: StateSpecs.combining(accumCoder, combineFn).","Register a coder for AccumT in the pipeline's CoderRegistry.","Simplify the accumulator type to one with an inferrable coder."],"exampleFix":"// before\nCombiningStateSpec<Long, Long, Long> spec = StateSpecs.combining(Sum.ofLongs());\n// after\nCombiningStateSpec<Long, Long, Long> spec = StateSpecs.combining(VarLongCoder.of(), Sum.ofLongs());","handlingStrategy":"validation","validationCode":"if (accumCoder == null) {\n  throw new IllegalStateException(\"Supply StateSpecs.combining(accumCoder, combineFn) with an explicit accumulator coder\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = StateSpecs.combining(fn);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"CombiningState\")) {\n    spec = StateSpecs.combining(accumCoder, fn);\n  } else throw e;\n}","preventionTips":["Always use the (Coder, CombineFn) overload of StateSpecs.combining","Register a coder for your accumulator type","Keep accumulator types simple and coder-friendly"],"tags":["java","apache-beam","state","coder-inference","combinefn"],"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"}