{"record":{"id":"4012175f71bac6b5","repo":"apache/beam","slug":"getclass-needs-to-override-getoutputcoder","errorCode":null,"errorMessage":"getClass() + \" needs to override getOutputCoder().\"","messagePattern":"getClass\\(\\) \\+ \" needs to override getOutputCoder\\(\\)\\.\"","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/io/Source.java","lineNumber":70,"sourceCode":"public abstract class Source<T> implements Serializable, HasDisplayData {\n  /**\n   * Checks that this source is valid, before it can be used in a pipeline.\n   *\n   * <p>It is recommended to use {@link Preconditions} for implementing this method.\n   */\n  public void validate() {}\n\n  /**\n   * @deprecated Override {@link #getOutputCoder()} instead.\n   */\n  @Deprecated\n  public Coder<T> getDefaultOutputCoder() {\n    // If the subclass doesn't override getDefaultOutputCoder(), hopefully it overrides the proper\n    // version - getOutputCoder(). Check that it does, before calling the method (if subclass\n    // doesn't override it, we'll call the default implementation and get infinite recursion).\n    try {\n      if (getClass().getMethod(\"getOutputCoder\").getDeclaringClass().equals(Source.class)) {\n        throw new UnsupportedOperationException(\n            getClass() + \" needs to override getOutputCoder().\");\n      }\n    } catch (NoSuchMethodException e) {\n      throw new RuntimeException(e);\n    }\n    return getOutputCoder();\n  }\n\n  /** Returns the {@code Coder} to use for the data read from this source. */\n  public Coder<T> getOutputCoder() {\n    // Call the old method for compatibility.\n    return getDefaultOutputCoder();\n  }\n\n  /**\n   * {@inheritDoc}\n   *\n   * <p>By default, does not register any display data. Implementors may override this method to","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/io/Source.java#L52-L88","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nclass MySource extends Source<String> {\n  // no coder override\n}\n\n// after\nclass MySource extends Source<String> {\n  @Override\n  public Coder<String> getDefaultOutputCoder() {\n    return StringUtf8Coder.of();\n  }\n}","handlingStrategy":"validation","validationCode":"// before Read.from(source)\nif (Source.class.equals(source.getClass().getMethod(\"getOutputCoder\").getDeclaringClass())) {\n  throw new IllegalStateException(\"Custom source must override getOutputCoder()/getDefaultOutputCoder()\");\n}","typeGuard":null,"tryCatchPattern":"try { Read.from(source); } catch (UnsupportedOperationException e) { log.error(\"Source {} lacks a coder override\", source.getClass(), e); throw e; }","preventionTips":["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."],"tags":["java","beam","coder","source","pipeline-construction"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}