{"record":{"id":"415c000607d81141","repo":"apache/beam","slug":"unable-to-infer-a-coder-for-mapstate-and-no-coder-was","errorCode":null,"errorMessage":"Unable to infer a coder for MapState and no Coder was specified. Please set a coder by either invoking StateSpecs.map(Coder<K> keyCoder, Coder<V> valueCoder) or by registering the coder in the Pipeline's CoderRegistry.","messagePattern":"Unable to infer a coder for MapState and no Coder was specified\\. Please set a coder by either invoking StateSpecs\\.map\\(Coder<K> keyCoder, Coder<V> valueCoder\\) 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":763,"sourceCode":"    public <ResultT> ResultT match(Cases<ResultT> cases) {\n      return cases.dispatchMap(keyCoder, valueCoder);\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public void offerCoders(Coder[] coders) {\n      if (this.keyCoder == null && coders[0] != null) {\n        this.keyCoder = (Coder<K>) coders[0];\n      }\n      if (this.valueCoder == null && coders[1] != null) {\n        this.valueCoder = (Coder<V>) coders[1];\n      }\n    }\n\n    @Override\n    public void finishSpecifying() {\n      if (keyCoder == null || valueCoder == null) {\n        throw new IllegalStateException(\n            \"Unable to infer a coder for MapState and no Coder\"\n                + \" was specified. Please set a coder by either invoking\"\n                + \" StateSpecs.map(Coder<K> keyCoder, Coder<V> valueCoder) or by registering the\"\n                + \" 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 MapStateSpec)) {\n        return false;\n      }\n\n      MapStateSpec<?, ?> that = (MapStateSpec<?, ?>) obj;","sourceCodeStart":745,"sourceCodeEnd":781,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/state/StateSpecs.java#L745-L781","documentation":"finishSpecifying on the MapState spec found keyCoder or valueCoder null: no coders were supplied via StateSpecs.map(keyCoder, valueCoder) and inference/offerCoders could not supply them by the time the spec was finalized. The map state spec's key/value types are the inputs at fault.","triggerScenarios":"Calling StateSpecs.map() (no-arg overload) where inference fails for the key type K or the value type V.","commonSituations":"Maps keyed or valued by custom classes without registered coders; partial inference success (key inferred but value not) still triggers the error.","solutions":["Pass both coders: StateSpecs.map(keyCoder, valueCoder).","Register coders for K and V in the pipeline's CoderRegistry.","Use types with inferrable coders for keys and values."],"exampleFix":"// before\nMapStateSpec<String, Long> spec = StateSpecs.map();\n// after\nMapStateSpec<String, Long> spec = StateSpecs.map(StringUtf8Coder.of(), VarLongCoder.of());","handlingStrategy":"validation","validationCode":"if (keyCoder == null || valueCoder == null) {\n  throw new IllegalStateException(\"Supply StateSpecs.map(keyCoder, valueCoder) with explicit coders\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  spec = StateSpecs.map();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"MapState\")) {\n    spec = StateSpecs.map(keyCoder, valueCoder);\n  } else throw e;\n}","preventionTips":["Always pass both key and value coders to StateSpecs.map()","Register coders for both K and V types","Avoid custom key types without registered coders"],"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"}