apache/beam · error · IllegalArgumentException

Could not decode the default value with the provided coder %

Error message

Could not decode the default value with the provided coder %s

What it means

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).

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/View.java:559

    @Override
    public T apply(T left, T right) {
      throw new IllegalArgumentException(
          "PCollection with more than one element "
              + "accessed as a singleton view. Consider using Combine.globally().asSingleton() to "
              + "combine the PCollection into a single value");
    }

    @Override
    public T identity() {
      if (hasDefault) {
        if (defaultValue == null) {
          return null;
        }
        try {
          return CoderUtils.decodeFromByteArray(valueCoder, defaultValue);
        } catch (CoderException e) {
          throw new IllegalArgumentException(
              String.format(
                  "Could not decode the default value with the provided coder %s", valueCoder));
        }
      } else {
        throw new IllegalArgumentException(
            "Empty PCollection accessed as a singleton view. "
                + "Consider setting withDefault to provide a default value");
      }
    }
  }

  /**
   * <b><i>For internal use only; no backwards-compatibility guarantees.</i></b>
   *
   * <p>Public only so a {@link PipelineRunner} may override its behavior.
   *
   * <p>See {@link View#asMultimap()}.
   */

View on GitHub (pinned to 12126d8942)

Solutions

  1. Recreate the default value in the same pipeline so it is serialized with the matching coder
  2. Ensure the coder passed to withCoder() can actually encode/decode the default value's runtime type
  3. Remove the explicit withCoder() and let Beam infer the coder from the default value
  4. Catch IllegalArgumentException around view access and rebuild the view with consistent coder + default

Example fix

// before
PCollectionView<Integer> view = pc.apply(View.asSingleton().withDefault(42).withCoder(legacyCoder));
// after
PCollectionView<Integer> view = pc.apply(View.asSingleton().withDefault(42)); // coder inferred to match default
Defensive patterns

Strategy: validation

Validate before calling

// Verify round-trip before building the view
byte[] serialized = CoderUtils.encodeToByteArray(valueCoder, defaultValue);
if (!CoderUtils.decodeFromByteArray(valueCoder, serialized).equals(defaultValue)) {
  throw new IllegalStateException("Coder cannot decode default value");
}

Try / catch

try { sideInput(view); } catch (IllegalArgumentException e) { /* rebuild view with matching coder/default */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/a8c9650b256e96d5. Report an issue: GitHub.