apache/iceberg · error · UnsupportedOperationException

Cannot modify DataFileWrapper wrapper via set

Error message

Cannot modify DataFileWrapper wrapper via set

What it means

DataFileWrapper in V1Metadata is a read-only StructLike view over a DataFile. Data files within manifests are immutable; set(pos, value) intentionally throws UnsupportedOperationException so callers cannot alter wrapped data-file fields (path, metrics, partitions) in place.

Solutions

  1. Do not call set; create a new DataFile via DataFiles.builder(table.spec()) and set fields on the builder
  2. Copy fields via get(pos) into a mutable Record if bulk modification is required
  3. Pass the underlying DataFile (not the wrapper) to APIs that need writable structs

Example fix

// before
dataFileWrapper.set(1, newPath);
// after
DataFile updated = DataFiles.builder(PartitionSpec.unpartitioned())
    .withPath(newPath)
    .withFileSizeInBytes(size)
    .build();
Defensive patterns

Strategy: validation

Validate before calling

if (df instanceof V1Metadata.DataFileWrapper) { throw new IllegalStateException("DataFileWrapper is read-only; use DataFiles.builder"); }

Type guard

boolean isReadOnlyDataFile(Object s) { return s instanceof V1Metadata.DataFileWrapper || s instanceof V2Metadata.DataFileWrapper; }

Try / catch

try { dfWrapper.set(pos, value); } catch (UnsupportedOperationException e) { throw new IllegalStateException("build a new DataFile instead", e); }

Prevention

When it happens

Trigger: Calling set(pos, value) on a DataFileWrapper obtained via wrap(dataFile), e.g. from generic StructLike writers or copy routines that mutate field values directly.

Common situations: Custom writers building manifests that treat DataFile StructLike as mutable; frameworks performing in-place record transformation on data file structs.

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/b83038a38026e8be. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/V1Metadata.java:358

    private DataFile wrapped = null;

    DataFileWrapper() {
      this.size = dataFileSchema(Types.StructType.of()).fields().size();
    }

    DataFileWrapper wrap(DataFile file) {
      this.wrapped = file;
      return this;
    }

    @Override
    public int size() {
      return size;
    }

    @Override
    public <T> void set(int pos, T value) {
      throw new UnsupportedOperationException("Cannot modify DataFileWrapper wrapper via set");
    }

    @Override
    public <T> T get(int pos, Class<T> javaClass) {
      return javaClass.cast(get(pos));
    }

    private Object get(int pos) {
      switch (pos) {
        case 0:
          return wrapped.location();
        case 1:
          return wrapped.format() != null ? wrapped.format().toString() : null;
        case 2:
          return wrapped.partition();
        case 3:
          return wrapped.recordCount();
        case 4:

View on GitHub (pinned to 86d9c8fc54)