apache/beam · error · CannotProvideCoderException

Failed to infer coder for DestinationT from type " +…

Error message

Failed to infer coder for DestinationT from type " + descriptor + ", please provide it explicitly by overriding getDestinationCoder()

What it means

DynamicDestinations.getDestinationCoderWithDefault() wraps CannotProvideCoderException when the CoderRegistry cannot infer a Coder for the DestinationT type parameter from its resolved type descriptor. Beam needs to serialize destinations (e.g. in FileResult coding) and requires an explicit coder when inference fails.

Solutions

  1. Override getDestinationCoder() in your DynamicDestinations subclass to return an explicit Coder<DestinationT>.
  2. Register a default coder for the destination type in the CoderRegistry.
  3. Use a simple destination type with an inferable coder (e.g. String, Integer, or a AvroRecord/POJO with a registered coder).

Example fix

// before
new DynamicDestinations<String, String, String>() { ... } // no getDestinationCoder
// after
new DynamicDestinations<String, String, String>() {
  @Override public Coder<String> getDestinationCoder() { return StringUtf8Coder.of(); }
}
Defensive patterns

Strategy: validation

Validate before calling

if (dynamicDestinations.getDestinationCoder() == null && registry.getCoder(destinationType) fails) -> provide coder

Try / catch

try { registry.getCoder(descriptor); } catch (CannotProvideCoderException e) { throw new IllegalStateException("Override getDestinationCoder() for type " + descriptor, e); }

Prevention

When it happens

Trigger: Using DynamicDestinations (e.g. TextIO.write().via() or WriteFiles) with a DestinationT type the CoderRegistry cannot infer — non-serializable types, generic/abstract types, or types without a registered default coder — without overriding getDestinationCoder().

Common situations: Custom DynamicDestinations subclasses with complex destination types (records, POJOs without coders, generics erased to type variables), commonly seen when building multi-file output partitions.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/FileBasedSink.java:353

    // Gets the destination coder. If the user does not provide one, try to find one in the coder
    // registry. If no coder can be found, throws CannotProvideCoderException.
    final Coder<DestinationT> getDestinationCoderWithDefault(CoderRegistry registry)
        throws CannotProvideCoderException {
      Coder<DestinationT> destinationCoder = getDestinationCoder();
      if (destinationCoder != null) {
        return destinationCoder;
      }
      // If dynamicDestinations doesn't provide a coder, try to find it in the coder registry.
      @Nullable TypeDescriptor<DestinationT> descriptor =
          extractFromTypeParameters(
              this,
              DynamicDestinations.class,
              new TypeVariableExtractor<
                  DynamicDestinations<UserT, DestinationT, OutputT>, DestinationT>() {});
      try {
        return registry.getCoder(descriptor);
      } catch (CannotProvideCoderException e) {
        throw new CannotProvideCoderException(
            "Failed to infer coder for DestinationT from type "
                + descriptor
                + ", please provide it explicitly by overriding getDestinationCoder()",
            e);
      }
    }
  }

  /** A naming policy for output files. */
  public abstract static class FilenamePolicy implements Serializable {
    /**
     * When a sink has requested windowed or triggered output, this method will be invoked to return
     * the file {@link ResourceId resource} to be created given the base output directory and a
     * {@link OutputFileHints} containing information about the file, including a suggested
     * extension (e.g. coming from {@link Compression}).
     *
     * <p>The policy must return unique and consistent filenames for different windows and panes.
     */

View on GitHub (pinned to 12126d8942)