{"record":{"id":"a8c9650b256e96d5","repo":"apache/beam","slug":"could-not-decode-the-default-value-with-the-provided-coder-s","errorCode":null,"errorMessage":"Could not decode the default value with the provided coder %s","messagePattern":"Could not decode the default value with the provided coder (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/View.java","lineNumber":559,"sourceCode":"\n    @Override\n    public T apply(T left, T right) {\n      throw new IllegalArgumentException(\n          \"PCollection with more than one element \"\n              + \"accessed as a singleton view. Consider using Combine.globally().asSingleton() to \"\n              + \"combine the PCollection into a single value\");\n    }\n\n    @Override\n    public T identity() {\n      if (hasDefault) {\n        if (defaultValue == null) {\n          return null;\n        }\n        try {\n          return CoderUtils.decodeFromByteArray(valueCoder, defaultValue);\n        } catch (CoderException e) {\n          throw new IllegalArgumentException(\n              String.format(\n                  \"Could not decode the default value with the provided coder %s\", valueCoder));\n        }\n      } else {\n        throw new IllegalArgumentException(\n            \"Empty PCollection accessed as a singleton view. \"\n                + \"Consider setting withDefault to provide a default value\");\n      }\n    }\n  }\n\n  /**\n   * <b><i>For internal use only; no backwards-compatibility guarantees.</i></b>\n   *\n   * <p>Public only so a {@link PipelineRunner} may override its behavior.\n   *\n   * <p>See {@link View#asMultimap()}.\n   */","sourceCodeStart":541,"sourceCodeEnd":577,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/View.java#L541-L577","documentation":"This error is thrown when a PCollectionView created via View.asSingleton() with a default value is materialized, but the stored serialized default bytes cannot be decoded with the coder currently attached to the value. Beam wraps the underlying CoderException in an IllegalArgumentException because a mismatch between the coder and the persisted default indicates the view was configured inconsistently (e.g. default value serialized with a different coder than the one specified via withCoder).","triggerScenarios":"Calling View.asSingleton().withDefault(value) where the serialized default bytes cannot be decoded by valueCoder — typically when withCoder() was used to attach a coder different from the one the default value was serialized with, or when the default bytes came from a pipeline/config that used a different coder.","commonSituations":"Changing a PCollection's element type or coder while reusing an old serialized default; deserializing a pipeline saved with an older Beam version whose coder format changed; supplying a custom Coder incompatible with the actual default value object.","solutions":["Recreate the default value in the same pipeline so it is serialized with the matching coder","Ensure the coder passed to withCoder() can actually encode/decode the default value's runtime type","Remove the explicit withCoder() and let Beam infer the coder from the default value","Catch IllegalArgumentException around view access and rebuild the view with consistent coder + default"],"exampleFix":"// before\nPCollectionView<Integer> view = pc.apply(View.asSingleton().withDefault(42).withCoder(legacyCoder));\n// after\nPCollectionView<Integer> view = pc.apply(View.asSingleton().withDefault(42)); // coder inferred to match default","handlingStrategy":"validation","validationCode":"// Verify round-trip before building the view\nbyte[] serialized = CoderUtils.encodeToByteArray(valueCoder, defaultValue);\nif (!CoderUtils.decodeFromByteArray(valueCoder, serialized).equals(defaultValue)) {\n  throw new IllegalStateException(\"Coder cannot decode default value\");\n}","typeGuard":null,"tryCatchPattern":"try { sideInput(view); } catch (IllegalArgumentException e) { /* rebuild view with matching coder/default */ }","preventionTips":["Let Beam infer the coder instead of calling withCoder() unless required","Round-trip test custom coders against default values in unit tests","Keep coder and default value definitions co-located so they change together"],"tags":["beam","coder","serialization","side-input"],"backgroundTag":"coder-decode-failure","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}