apache/iceberg · error · UnsupportedOperationException

%s does not implement addFile

Error message

%s does not implement addFile

What it means

RewriteFiles.addFile(DataFile) is a default interface method that throws UnsupportedOperationException when an implementation does not override it. Rewriting data files requires the operation to record replacement files; this default signals the implementation in use does not implement the add half of the rewrite contract.

Source

Thrown at api/src/main/java/org/apache/iceberg/RewriteFiles.java:81

   * @return this for method chaining
   */
  default RewriteFiles deleteFile(DeleteFile deleteFile) {
    throw new UnsupportedOperationException(
        this.getClass().getName() + " does not implement deleteFile");
  }

  /**
   * Add a new data file.
   *
   * <p>This rewrite operation may change the size or layout of the data files. When applicable, it
   * is also recommended to discard already deleted records while rewriting data files. However, the
   * set of live data records must never change.
   *
   * @param dataFile a new data file
   * @return this for method chaining
   */
  default RewriteFiles addFile(DataFile dataFile) {
    throw new UnsupportedOperationException(
        this.getClass().getName() + " does not implement addFile");
  }

  /**
   * Add a new delete file.
   *
   * <p>This rewrite operation may change the size or layout of the delete files. When applicable,
   * it is also recommended to discard delete records for files that are no longer part of the table
   * state. However, the set of applicable delete records must never change.
   *
   * @param deleteFile a new delete file
   * @return this for method chaining
   */
  default RewriteFiles addFile(DeleteFile deleteFile) {
    throw new UnsupportedOperationException(
        this.getClass().getName() + " does not implement addFile");
  }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Use the standard RewriteFiles from table.newRewrite(), which is implemented by BaseRewriteFiles with addFile(DataFile) support.
  2. Align the api and core Iceberg artifact versions on the classpath so the implementation overrides all addFile overloads.
  3. If you implement RewriteFiles yourself, override addFile(DataFile) to record the new data file.

Example fix

// before
RewriteFiles rewrite = (RewriteFiles) Proxy.newProxyInstance(...); // partial stub
rewrite.addFile(newFile); // UnsupportedOperationException
// after
RewriteFiles rewrite = table.newRewrite();
rewrite.addFile(newFile);
Defensive patterns

Strategy: try-catch

Validate before calling

Preconditions.checkArgument(!(rewrite instanceof UnsupportedOperationExceptionThrowingStub), "use table.newRewrite()");

Type guard

static boolean supportsAddDataFile(RewriteFiles rf) { return rf instanceof BaseRewriteFiles; }

Try / catch

try {
  rewrite.addFile(newDataFile);
} catch (UnsupportedOperationException e) {
  throw new IllegalStateException("This RewriteFiles does not implement addFile(DataFile)", e);
}

Prevention

When it happens

Trigger: Calling addFile(DataFile) on a RewriteFiles instance that is not the standard BaseRewriteFiles — e.g. a stub/test double, a catalog-supplied wrapper, or code path (makeRewriteDataFiles, doReplace) wired to an implementation lacking the method.

Common situations: Custom table operation classes in unit tests; mixed api/core versions where the core module predates the current RewriteFiles surface; third-party catalogs returning custom SnapshotProducer implementations.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/f6893f85fd91c253. Report an issue: GitHub.