apache/beam · error · CannotProvideCoderException

%s is not one of the common types.

Error message

%s is not one of the common types.

What it means

The CoderRegistry's built-in common-types coder provider only resolves coders for a fixed set of well-known Java types (e.g. String, Integer, Long, byte[], KVs). If coderFor is called with a TypeDescriptor whose raw type is not in that map, it throws CannotProvideCoderException stating the type is not one of the common types.

Source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/coders/CoderRegistry.java:159

      builder.put(
          ValueKind.class, CoderProviders.fromStaticMethods(ValueKind.class, ValueKindCoder.class));
      builder.put(Void.class, CoderProviders.fromStaticMethods(Void.class, VoidCoder.class));
      builder.put(
          byte[].class, CoderProviders.fromStaticMethods(byte[].class, ByteArrayCoder.class));
      builder.put(
          IntervalWindow.class,
          CoderProviders.forCoder(
              TypeDescriptor.of(IntervalWindow.class), IntervalWindow.getCoder()));
      commonTypesToCoderProviders = builder.build();
    }

    @Override
    public <T> Coder<T> coderFor(
        TypeDescriptor<T> typeDescriptor, List<? extends Coder<?>> componentCoders)
        throws CannotProvideCoderException {
      CoderProvider factory = commonTypesToCoderProviders.get(typeDescriptor.getRawType());
      if (factory == null) {
        throw new CannotProvideCoderException(
            String.format("%s is not one of the common types.", typeDescriptor));
      }
      return factory.coderFor(typeDescriptor, componentCoders);
    }
  }

  static {
    // Register the standard coders first so they are chosen over ServiceLoader ones
    List<CoderProvider> codersToRegister = new ArrayList<>();
    codersToRegister.add(new CommonTypes());

    // Enumerate all the CoderRegistrars in a deterministic order, adding all coders to register
    Set<CoderProviderRegistrar> registrars = Sets.newTreeSet(ObjectsClassComparator.INSTANCE);
    registrars.addAll(
        Lists.newArrayList(
            ServiceLoader.load(CoderProviderRegistrar.class, ReflectHelpers.findClassLoader())));

    // DefaultCoder should have the highest precedence and SerializableCoder the lowest

View on GitHub (pinned to 12126d8942)

Solutions

  1. Register a coder for the custom type: registry.registerCoderForClass(MyType.class, MyTypeCoder.class)
  2. Annotate the class with @DefaultCoder(MyTypeCoder.class)
  3. Provide the coder explicitly at the transform (e.g. apply(...).setCoder(...)) or via getCoder overrides
  4. If the type genuinely is a common type, check the TypeDescriptor's raw type — generics erasure may have resolved it to an unexpected raw type

Example fix

// before
PCollection<MyType> out = rows.apply(ParDo.of(fn)); // CannotProvideCoderException
// after
p.getCoderRegistry().registerCoderForClass(MyType.class, new MyTypeCoder());
PCollection<MyType> out = rows.apply(ParDo.of(fn));
Defensive patterns

Strategy: fallback

Validate before calling

CoderRegistry registry = p.getCoderRegistry();
if (registry.getCoder(MyType.class) == null) { registry.registerCoderForClass(MyType.class, new MyTypeCoder()); }

Type guard

boolean hasDefaultCoder = java.util.Arrays.stream(CommonTypes.values()).anyMatch(t -> t.cls.equals(typeDescriptor.getRawType()));

Try / catch

try {
  coder = registry.getCoder(MyType.class);
} catch (CannotProvideCoderException e) {
  coder = new MyTypeCoder(); // explicit fallback
}

Prevention

When it happens

Trigger: Calling CoderRegistry.getCoder / getDefaultOutputCoder for a custom class that relies on the registry's default common-type resolution rather than having a registered coder or @DefaultCoder annotation.

Common situations: Custom POJO / AutoValue element types in a DoFn output without a registered coder; upgrading Beam where the inferred type changed; forgetting registerCoderForClass for user types before applying transforms.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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