{"record":{"id":"9eea0ed822371c22","repo":"apache/beam","slug":"unable-to-get-state-coder","errorCode":null,"errorMessage":"Unable to get state coder","messagePattern":"Unable to get state coder","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"sdks/java/extensions/ordered/src/main/java/org/apache/beam/sdk/extensions/ordered/OrderedEventProcessor.java","lineNumber":130,"sourceCode":"    Coder<EventKeyT> keyCoder;\n    try {\n      keyCoder = handler.getKeyCoder(pipeline, input.getCoder());\n    } catch (CannotProvideCoderException e) {\n      throw new RuntimeException(\"Unable to get key coder\", e);\n    }\n\n    Coder<EventT> eventCoder;\n    try {\n      eventCoder = handler.getEventCoder(pipeline, input.getCoder());\n    } catch (CannotProvideCoderException e) {\n      throw new RuntimeException(\"Unable to get event coder\", e);\n    }\n\n    Coder<StateT> stateCoder;\n    try {\n      stateCoder = handler.getStateCoder(pipeline);\n    } catch (CannotProvideCoderException e) {\n      throw new RuntimeException(\"Unable to get state coder\", e);\n    }\n\n    Coder<ResultT> resultCoder;\n    try {\n      resultCoder = handler.getResultCoder(pipeline);\n    } catch (CannotProvideCoderException e) {\n      throw new RuntimeException(\"Unable to get result coder\", e);\n    }\n\n    KvCoder<EventKeyT, ResultT> mainOutputCoder = KvCoder.of(keyCoder, resultCoder);\n    KvCoder<EventKeyT, OrderedProcessingStatus> processingStatusCoder =\n        KvCoder.of(keyCoder, getOrderedProcessingStatusCoder(pipeline));\n    KvCoder<EventKeyT, KV<Long, UnprocessedEvent<EventT>>> unprocessedEventsCoder =\n        KvCoder.of(\n            keyCoder, KvCoder.of(VarLongCoder.of(), new UnprocessedEventCoder<>(eventCoder)));\n\n    if (handler instanceof OrderedProcessingGlobalSequenceHandler) {\n      OrderedProcessingGlobalSequenceHandler<EventT, EventKeyT, StateT, ResultT>","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/extensions/ordered/src/main/java/org/apache/beam/sdk/extensions/ordered/OrderedEventProcessor.java#L112-L148","documentation":"OrderedEventProcessor.expand() requests the state type StateT coder via handler.getStateCoder(pipeline). Unlike key/event coders it is not inferred from the input PCollection, so if the handler cannot supply one (CannotProvideCoderException), this RuntimeException is thrown. State must be serializable because Beam persists per-key state and buffers.","triggerScenarios":"Building OrderedEventProcessor with a state class that has no registered coder provider and no explicit coder configured on the handler; calling expand() where getStateCoder relies on type inference that fails for the custom StateT.","commonSituations":"State classes without @DefaultCoder or CoderProvider registration; using nested generic state types whose TypeDescriptor cannot be materialized; forgetting to pass a coder supplier when constructing the handler.","solutions":["Provide an explicit state coder when constructing the handler/builder (e.g. usingSerializableCoder/AvroCoder supplier).","Annotate the state class with @DefaultCoder or register a CoderProvider in the pipeline's CoderRegistry.","Override getStateCoder in a handler subclass to return a concrete Coder<StateT>.","Check that the StateT generic parameter is concrete at the call site."],"exampleFix":"// before\nOrderedEventProcessor<KeyT, EventT, StateT, ...> p = OrderedEventProcessor.builder(handler)...build();\n// after (handler supplies coder)\nOrderedEventProcessor.Builder<...> b = OrderedEventProcessor.builder(handlerWithStateCoder(SerializableCoder.of(MyState.class)));","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(stateCoderSupplier, \"state coder supplier must be configured on the handler before build()\");","typeGuard":"static <StateT> boolean stateCoderConfigured(ComposedAccumulatingProcessingHandler<?, ?, StateT, ?, ?> h) {\n  try { return h.getStateCoder(pipeline) != null; } catch (CannotProvideCoderException e) { return false; }\n}","tryCatchPattern":"try {\n  handler.getStateCoder(pipeline);\n} catch (CannotProvideCoderException e) {\n  throw new IllegalStateException(\"Provide an explicit Coder<StateT> in the handler configuration\", e);\n}","preventionTips":["Configure the state coder explicitly when building the handler","Keep state classes simple and codable (Avro/Serializable)","Test pipeline expansion in CI to catch missing coders early"],"tags":["apache-beam","coder","state","pipeline-construction"],"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"}