apache/iceberg · error · UnsupportedOperationException

Does not support schema getter

Error message

Does not support schema getter

What it means

FileScanTask.schema() is a default interface method that returns the schema used to read the task's data file. Most implementations do not carry a schema, so the default throws UnsupportedOperationException; callers must handle implementations that cannot supply one.

Source

Thrown at api/src/main/java/org/apache/iceberg/FileScanTask.java:35

 * under the License.
 */
package org.apache.iceberg;

import java.util.List;
import org.apache.iceberg.util.ScanTaskUtil;

/** A scan task over a range of bytes in a single data file. */
public interface FileScanTask extends ContentScanTask<DataFile>, SplittableScanTask<FileScanTask> {
  /**
   * A list of {@link DeleteFile delete files} to apply when reading the task's data file.
   *
   * @return a list of delete files to apply
   */
  List<DeleteFile> deletes();

  /** Return the schema for this file scan task. */
  default Schema schema() {
    throw new UnsupportedOperationException("Does not support schema getter");
  }

  @Override
  default long sizeBytes() {
    return length() + ScanTaskUtil.contentSizeInBytes(deletes());
  }

  @Override
  default int filesCount() {
    return 1 + deletes().size();
  }

  @Override
  default boolean isFileScanTask() {
    return true;
  }

  @Override

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Only call schema() on tasks known to support it (check instanceof or a capability flag), otherwise use the table's current schema
  2. For serialization, skip or omit the schema field when UnsupportedOperationException is thrown
  3. If you own the FileScanTask implementation, override schema() to return the read schema

Example fix

// before
Schema schema = task.schema();
// after
Schema schema;
try {
  schema = task.schema();
} catch (UnsupportedOperationException e) {
  schema = table.schema();
}
Defensive patterns

Strategy: try-catch

Validate before calling

boolean hasSchema = task.getClass().getName().contains("SchemaAware"); // or capability check

Type guard

boolean supportsSchema(FileScanTask t) {
  try { t.schema(); return true; } catch (UnsupportedOperationException e) { return false; }
}

Try / catch

try {
  schema = task.schema();
} catch (UnsupportedOperationException e) {
  schema = table.schema();
}

Prevention

When it happens

Trigger: Calling schema() on a FileScanTask produced by an implementation that does not override it, e.g. generic task serialization (toJson) or test assertion helpers (assertFileScanTaskEquals) running against basic scan tasks.

Common situations: Custom metadata/logic that serializes scan tasks from engines whose tasks don't embed schemas; unit-test comparison utilities applied to tasks from sources lacking schema support.

Related errors


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