{"record":{"id":"5985edcbb273fbae","repo":"apache/beam","slug":"unable-to-infer-a-coder-for-combiningwithcontextstate-and-no","errorCode":null,"errorMessage":"Unable to infer a coder for CombiningWithContextState and no Coder was specified. Please set a coder by either invoking StateSpecs.combiningWithcontext(Coder<AccumT> accumCoder, CombineFnWithContext<InputT, AccumT, OutputT> combineFn) or by registering the coder in the Pipeline's CoderRegistry.","messagePattern":"Unable to infer a coder for CombiningWithContextState and no Coder was specified\\. Please set a coder by either invoking StateSpecs\\.combiningWithcontext\\(Coder<AccumT> accumCoder, CombineFnWithContext<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":575,"sourceCode":"    public <ResultT> ResultT match(Cases<ResultT> cases) {\n      throw new UnsupportedOperationException(\n          String.format(\n              \"%s is for internal use only and does not support case dispatch\",\n              getClass().getSimpleName()));\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void offerCoders(Coder[] coders) {\n      if (this.accumCoder == null && coders[2] != null) {\n        this.accumCoder = (Coder<AccumT>) coders[2];\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                + \" CombiningWithContextState and no Coder was specified.\"\n                + \" Please set a coder by either invoking\"\n                + \" StateSpecs.combiningWithcontext(Coder<AccumT> accumCoder,\"\n                + \" CombineFnWithContext<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 CombiningWithContextStateSpec)) {\n        return false;\n      }","sourceCodeStart":557,"sourceCodeEnd":593,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L557-L593","documentation":"A CombiningWithContextState spec created without an explicit accumulator coder cannot infer one at finishSpecifying time. StateSpecs throws IllegalStateException when accumCoder is null, telling you to use StateSpecs.combiningWithContext(Coder, CombineFnWithContext).","triggerScenarios":"Calling StateSpecs.combiningWithContext(CombineFnWithContext) (overload without Coder<AccumT>) where the accumulator type's coder cannot be inferred.","commonSituations":"Custom CombineFnWithContext with a custom accumulator class lacking a registered coder; pipelines where CoderRegistry inference fails for generic accumulator types.","solutions":["Use StateSpecs.combiningWithContext(accumCoder, combineFn) with an explicit coder.","Register a coder for AccumT in the pipeline's CoderRegistry.","Change the accumulator type to one with an inferrable coder."],"exampleFix":"// before\nStateSpecs.combiningWithContext(myContextualFn);\n// after\nStateSpecs.combiningWithContext(VarLongCoder.of(), myContextualFn);","handlingStrategy":"validation","validationCode":"if (accumCoder == null) {\n  throw new IllegalStateException(\"Supply StateSpecs.combiningWithContext(accumCoder, combineFn) with an explicit accumulator coder\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = StateSpecs.combiningWithContext(fn);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"CombiningWithContextState\")) {\n    spec = StateSpecs.combiningWithContext(accumCoder, fn);\n  } else throw e;\n}","preventionTips":["Always use the (Coder, CombineFnWithContext) overload","Register a coder for your accumulator type in the CoderRegistry","Verify coder inference in unit tests before running on a runner"],"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"}