{"record":{"id":"c64a0e7b12570e6e","repo":"apache/beam","slug":"unable-to-determine-accumulator-coder-for-from","errorCode":null,"errorMessage":"Unable to determine accumulator coder for {} from {}","messagePattern":"Unable to determine accumulator coder for (.+?) from (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java","lineNumber":304,"sourceCode":"\n  /**\n   * <b><i>For internal use only; no backwards-compatibility guarantees.</i></b>\n   *\n   * <p>Create a state spec for values that use a {@link CombineFn} to automatically merge multiple\n   * {@code InputT}s into a single {@code OutputT}.\n   *\n   * <p>This determines the {@code Coder<AccumT>} from the given {@code Coder<InputT>}, and should\n   * only be used to initialize static values.\n   */\n  @Internal\n  public static <InputT, AccumT, OutputT>\n      StateSpec<CombiningState<InputT, AccumT, OutputT>> combiningFromInputInternal(\n          Coder<InputT> inputCoder, CombineFn<InputT, AccumT, OutputT> combineFn) {\n    try {\n      Coder<AccumT> accumCoder = combineFn.getAccumulatorCoder(STANDARD_REGISTRY, inputCoder);\n      return combiningInternal(accumCoder, combineFn);\n    } catch (CannotProvideCoderException e) {\n      throw new IllegalArgumentException(\n          \"Unable to determine accumulator coder for \"\n              + combineFn.getClass().getSimpleName()\n              + \" from \"\n              + inputCoder,\n          e);\n    }\n  }\n\n  private static <InputT, AccumT, OutputT>\n      StateSpec<CombiningState<InputT, AccumT, OutputT>> combiningInternal(\n          Coder<AccumT> accumCoder, CombineFn<InputT, AccumT, OutputT> combineFn) {\n    return new CombiningStateSpec<>(accumCoder, combineFn);\n  }\n\n  private static <InputT, AccumT, OutputT>\n      StateSpec<CombiningState<InputT, AccumT, OutputT>> combiningInternal(\n          Coder<AccumT> accumCoder, CombineFnWithContext<InputT, AccumT, OutputT> combineFn) {\n    return new CombiningWithContextStateSpec<>(accumCoder, combineFn);","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L286-L322","documentation":"StateSpecs.combiningFromInputInternal() infers the accumulator coder by calling CombineFn.getAccumulatorCoder() against the standard CoderRegistry. When the CombineFn cannot provide an accumulator coder given the input coder (CannotProvideCoderException), Beam wraps it in an IllegalArgumentException naming the CombineFn class and input coder. Without an accumulator coder the CombiningState cannot be serialized.","triggerScenarios":"Creating a state spec via StateSpecs.combining(getCombineFn()) (or combiningFromInputInternal internally) where the CombineFn's getAccumulatorCoder throws CannotProvideCoderException — typically a custom CombineFn lacking an accumulator CoderProvider or a generic accumulator type Beam cannot infer from the input coder.","commonSituations":"Custom CombineFn with an accumulator type not derivable (e.g. generic class AccumT without registerCoderProvider); using combine functions over custom input types without registered coders; Avro/POJO types missing @DefaultCoder annotations.","solutions":["Override getAccumulatorCoder(CoderRegistry, Coder<InputT>) in your CombineFn and return an explicit accumulator coder.","Register a CoderProvider for the accumulator type, or annotate the accumulator class with @DefaultCoder(...).","Use the StateSpecs.combining(accumCoder, combineFn) overload that supplies the accumulator coder explicitly."],"exampleFix":"// before\nclass MyFn extends CombineFn<Long, Accum, Long> { /* no getAccumulatorCoder */ }\n\n// after\n@Override\npublic Coder<Accum> getAccumulatorCoder(CoderRegistry registry, Coder<Long> inputCoder) {\n  return accumulatorCoder;\n}","handlingStrategy":"validation","validationCode":"try {\n  combineFn.getAccumulatorCoder(CoderRegistry.createDefault(), inputCoder);\n} catch (CannotProvideCoderException e) {\n  // supply an explicit accumulator coder via StateSpecs.combining(accumCoder, combineFn)\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = StateSpecs.combining(combineFn);\n} catch (IllegalArgumentException e) {\n  spec = StateSpecs.combining(explicitAccumCoder, combineFn);\n}","preventionTips":["Always override getAccumulatorCoder() in custom CombineFns","Register coders for accumulator types with @DefaultCoder or CoderRegistry#registerCoderProvider","Prefer the explicit StateSpecs.combining(accumCoder, combineFn) overload in production code"],"tags":["apache-beam","coders","combinefn"],"backgroundTag":"type-mismatch","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"}