apache/beam · error · UnsupportedOperationException
getClass() + " needs to override getOutputCoder()."
Error message
getClass() + " needs to override getOutputCoder()."
What it means
Source.getDefaultOutputCoder() throws this UnsupportedOperationException when a concrete Source subclass inherits both getDefaultOutputCoder() and getOutputCoder() from Source itself (neither is overridden). Calling getOutputCoder() would recurse infinitely, so Source detects via reflection that getOutputCoder() is still declared by Source.class and fails fast with this message instead.
Source
Thrown at sdks/java/core/src/main/java/org/apache/beam/sdk/io/Source.java:70
public abstract class Source<T> implements Serializable, HasDisplayData {
/**
* Checks that this source is valid, before it can be used in a pipeline.
*
* <p>It is recommended to use {@link Preconditions} for implementing this method.
*/
public void validate() {}
/**
* @deprecated Override {@link #getOutputCoder()} instead.
*/
@Deprecated
public Coder<T> getDefaultOutputCoder() {
// If the subclass doesn't override getDefaultOutputCoder(), hopefully it overrides the proper
// version - getOutputCoder(). Check that it does, before calling the method (if subclass
// doesn't override it, we'll call the default implementation and get infinite recursion).
try {
if (getClass().getMethod("getOutputCoder").getDeclaringClass().equals(Source.class)) {
throw new UnsupportedOperationException(
getClass() + " needs to override getOutputCoder().");
}
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
return getOutputCoder();
}
/** Returns the {@code Coder} to use for the data read from this source. */
public Coder<T> getOutputCoder() {
// Call the old method for compatibility.
return getDefaultOutputCoder();
}
/**
* {@inheritDoc}
*
* <p>By default, does not register any display data. Implementors may override this method toView on GitHub (pinned to 12126d8942)
Solutions
- Override getOutputCoder() in your Source subclass to return the appropriate Coder<T> (e.g. SerializableCoder.of(MyType.class)).
- Alternatively override getDefaultOutputCoder() with the correct coder if your source prefers that hook.
- If using a third-party source, upgrade it to a Beam version compatible with your SDK version.
Example fix
// before
class MySource extends Source<String> {
// no coder override
}
// after
class MySource extends Source<String> {
@Override
public Coder<String> getDefaultOutputCoder() {
return StringUtf8Coder.of();
}
} Defensive patterns
Strategy: validation
Validate before calling
// before Read.from(source)
if (Source.class.equals(source.getClass().getMethod("getOutputCoder").getDeclaringClass())) {
throw new IllegalStateException("Custom source must override getOutputCoder()/getDefaultOutputCoder()");
} Try / catch
try { Read.from(source); } catch (UnsupportedOperationException e) { log.error("Source {} lacks a coder override", source.getClass(), e); throw e; } Prevention
- Always override getDefaultOutputCoder() in custom Source subclasses.
- Add a unit test that runs a small pipeline with the source to surface missing coder overrides early.
When it happens
Trigger: Using a custom Source subclass (or an old/removed built-in source) in a Read.from(...) transform where the class overrides neither getOutputCoder() nor getDefaultOutputCoder(), and the pipeline resolves the coder during graph construction.
Common situations: Writing a custom Source and forgetting to override getOutputCoder(); upgrading Beam where a base-class default coder was removed; copying a source skeleton that left the coder method unimplemented.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- Invalid encoded string length: {}
- cannot encode a null String
- cannot encode a null Integer
- error when decoding a textual integer
- Cannot encode null window
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/4012175f71bac6b5.
Report an issue: GitHub.