{"record":{"id":"a6f2df2e7a53066c","repo":"apache/beam","slug":"could-not-obtain-a-coder-for-the-accumulator","errorCode":null,"errorMessage":"Could not obtain a Coder for the accumulator","messagePattern":"Could not obtain a Coder for the accumulator","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/CombineTranslation.java","lineNumber":109,"sourceCode":"        // FunctionSpec.\n        return null;\n      }\n    }\n\n    private static <K, InputT, AccumT> Coder<AccumT> extractAccumulatorCoder(\n        GlobalCombineFn<InputT, AccumT, ?> combineFn,\n        AppliedPTransform<PCollection<KV<K, InputT>>, ?, Combine.PerKey<K, InputT, ?>> transform)\n        throws IOException {\n      try {\n        @SuppressWarnings(\"unchecked\")\n        PCollection<KV<K, InputT>> mainInput =\n            (PCollection<KV<K, InputT>>)\n                Iterables.getOnlyElement(TransformInputs.nonAdditionalInputs(transform));\n        return combineFn.getAccumulatorCoder(\n            transform.getPipeline().getCoderRegistry(),\n            ((KvCoder<K, InputT>) mainInput.getCoder()).getValueCoder());\n      } catch (CannotProvideCoderException e) {\n        throw new IOException(\"Could not obtain a Coder for the accumulator\", e);\n      }\n    }\n  }\n\n  /** A {@link PTransformTranslation.TransformPayloadTranslator} for {@link Combine.Globally}. */\n  public static class CombineGloballyPayloadTranslator\n      implements PTransformTranslation.TransformPayloadTranslator<Combine.Globally<?, ?>> {\n    private CombineGloballyPayloadTranslator() {}\n\n    @Override\n    public String getUrn() {\n      return PTransformTranslation.COMBINE_GLOBALLY_TRANSFORM_URN;\n    }\n\n    @Override\n    public FunctionSpec translate(\n        AppliedPTransform<?, ?, Combine.Globally<?, ?>> transform, SdkComponents components)\n        throws IOException {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/CombineTranslation.java#L91-L127","documentation":"CombineTranslation.extractAccumulatorCoder asks the CombineFn for an accumulator Coder via getAccumulatorCoder; when the coder registry cannot provide one (CannotProvideCoderException), it wraps it in this IOException while converting the transform to its RunnerApi form.","triggerScenarios":"Translating a Combine.GloballyKeysSorted/PerKey transform whose main input is a KvCoder whose value type has no registered coder — e.g. a custom type never registered with the CoderRegistry, or input PCollections created without coders in a non-Java-created pipeline.","commonSituations":"Custom accumulator types without CoderProvider registration; values built with generics/anonymous classes the registry can't infer; pipelines deserialized from other SDKs then re-translated in Java.","solutions":["Register a coder for the accumulator/value type: pipeline.getCoderRegistry().registerCoderForType(TypeDescriptor.of(MyAccum.class), MyAccumCoder::new)","Implement getAccumulatorCoder properly or provide a CoderProvider via @AutoService CoderProviderRegistrar","Ensure the main input PCollection carries a KvCoder with a concrete value coder","Use pipeline.getCoderRegistry() verification (coderOf) before translation to test the lookup"],"exampleFix":"// before\nPipeline p = ...; // no registration for MyAccum\n// after\np.getCoderRegistry().registerCoderForType(\n    TypeDescriptor.of(MyAccum.class), new MyAccumCoder());","handlingStrategy":"validation","validationCode":"Coder<K> valueCoder = ((KvCoder<K, InputT>) mainInput.getCoder()).getValueCoder();\npipeline.getCoderRegistry().getCoder(valueTypeDescriptor); // throws CannotProvideCoderException early if unresolvable","typeGuard":null,"tryCatchPattern":"try {\n  return CoderTranslation.toProto(transform, components);\n} catch (IOException e) {\n  if (e.getMessage().contains(\"Could not obtain a Coder for the accumulator\")) {\n    throw new IllegalStateException(\"register a coder for the accumulator/value type\", e);\n  }\n  throw e;\n}","preventionTips":["Register coders for all custom types via CoderRegistry or CoderProvider","Ensure combine inputs carry concrete KvCoders","Prefer lambda-free CombineFn implementations with explicit type parameters"],"tags":["java","beam","combine","coder"],"backgroundTag":"resource-not-found","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"}