apache/beam · error · RuntimeException

Unable to apply Create

Error message

Unable to apply Create %s using Coder %s.

What it means

After choosing a coder, Create.expand() serializes its elements into a CreateSource via CreateSource.fromIterable; if that serialization throws IOException (the coder failed to encode the elements), Beam wraps it in this RuntimeException. The coder was accepted by inference but is incompatible with the actual element values at encode time.

Solutions

  1. Verify the coder's type parameter matches the element type passed to Create.of (fix generics / explicit type witness).
  2. If using AvroCoder, confirm the schema/class matches the elements.
  3. Check elements for nulls or non-serializable fields the chosen coder cannot handle; use a coder that supports them (e.g. NullableCoder, or fix the POJO).
  4. Run the coder standalone: Coder.encode on one element in a unit test to reproduce and debug the IOException.

Example fix

// before
p.apply(Create.of(listOfDogs).withCoder(AvroCoder.of(Cat.class))); // encode fails
// after
p.apply(Create.of(listOfDogs).withCoder(AvroCoder.of(Dog.class)));
Defensive patterns

Strategy: try-catch

Validate before calling

try { coder.encode(sampleElem, new ByteArrayOutputStream(), Coder.Context.OUTER); } catch (Exception e) { /* coder incompatible with elements */ }

Type guard

boolean coderCanEncode(Coder<T> c, T sample) { try { c.encode(sample, new ByteArrayOutputStream(), Coder.Context.OUTER); return true; } catch (Exception e) { return false; } }

Try / catch

try { p.apply(Create.of(elems).withCoder(coder)); } catch (RuntimeException e) { if (e.getMessage() != null && e.getMessage().startsWith("Unable to apply Create")) { /* verify coder type matches elements */ } throw e; }

Prevention

When it happens

Trigger: Create.of(elems).withCoder(c) where c cannot actually encode the runtime elements — e.g. a coder expecting a different type than supplied, AvroCoder misconfigured with wrong schema class, or a coder that fails on null values in the list.

Common situations: Passing a coder typed for a subclass/superclass mismatch; AvroCoder with wrong schema; custom coder throwing on encode (e.g. non-serializable fields in SerializableCoder).

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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

Appendix: source

Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/Create.java:442

                .apply(
                    MapElements.via(
                        new SimpleFunction<byte[], T>() {
                          @Override
                          public T apply(byte[] input) {
                            try {
                              return CoderUtils.decodeFromByteArray(capturedCoder, encodedElement);
                            } catch (CoderException exn) {
                              throw new RuntimeException(exn);
                            }
                          }
                        }))
                .setCoder(coder);
          }
        }
        CreateSource<T> source = CreateSource.fromIterable(elems, coder);
        return input.getPipeline().apply(Read.from(source));
      } catch (IOException e) {
        throw new RuntimeException(
            String.format("Unable to apply Create %s using Coder %s.", this, coder), e);
      }
    }

    /////////////////////////////////////////////////////////////////////////////

    /** The elements of the resulting PCollection. */
    private final transient Iterable<T> elems;

    /** The coder used to encode the values to and from a binary representation. */
    private final transient Optional<Coder<T>> coder;

    /** The value type. */
    private final transient Optional<TypeDescriptor<T>> typeDescriptor;

    /** Whether to unconditionally implement this via reading a CreateSource. */
    private final transient boolean alwaysUseRead;

View on GitHub (pinned to 12126d8942)