{"record":{"id":"b83038a38026e8be","repo":"apache/iceberg","slug":"cannot-modify-datafilewrapper-wrapper-via-set","errorCode":null,"errorMessage":"Cannot modify DataFileWrapper wrapper via set","messagePattern":"Cannot modify DataFileWrapper wrapper via set","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/V1Metadata.java","lineNumber":358,"sourceCode":"    private DataFile wrapped = null;\n\n    DataFileWrapper() {\n      this.size = dataFileSchema(Types.StructType.of()).fields().size();\n    }\n\n    DataFileWrapper wrap(DataFile file) {\n      this.wrapped = file;\n      return this;\n    }\n\n    @Override\n    public int size() {\n      return size;\n    }\n\n    @Override\n    public <T> void set(int pos, T value) {\n      throw new UnsupportedOperationException(\"Cannot modify DataFileWrapper wrapper via set\");\n    }\n\n    @Override\n    public <T> T get(int pos, Class<T> javaClass) {\n      return javaClass.cast(get(pos));\n    }\n\n    private Object get(int pos) {\n      switch (pos) {\n        case 0:\n          return wrapped.location();\n        case 1:\n          return wrapped.format() != null ? wrapped.format().toString() : null;\n        case 2:\n          return wrapped.partition();\n        case 3:\n          return wrapped.recordCount();\n        case 4:","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/V1Metadata.java#L340-L376","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom writers building manifests that treat DataFile StructLike as mutable; frameworks performing in-place record transformation on data file structs.","solutions":["Do not call set; create a new DataFile via DataFiles.builder(table.spec()) and set fields on the builder","Copy fields via get(pos) into a mutable Record if bulk modification is required","Pass the underlying DataFile (not the wrapper) to APIs that need writable structs"],"exampleFix":"// before\ndataFileWrapper.set(1, newPath);\n// after\nDataFile updated = DataFiles.builder(PartitionSpec.unpartitioned())\n    .withPath(newPath)\n    .withFileSizeInBytes(size)\n    .build();","handlingStrategy":"validation","validationCode":"if (df instanceof V1Metadata.DataFileWrapper) { throw new IllegalStateException(\"DataFileWrapper is read-only; use DataFiles.builder\"); }","typeGuard":"boolean isReadOnlyDataFile(Object s) { return s instanceof V1Metadata.DataFileWrapper || s instanceof V2Metadata.DataFileWrapper; }","tryCatchPattern":"try { dfWrapper.set(pos, value); } catch (UnsupportedOperationException e) { throw new IllegalStateException(\"build a new DataFile instead\", e); }","preventionTips":["Use DataFiles.builder(table.spec()) to construct modified data files","Never mutate data-file structs read from manifests","Keep the underlying DataFile, not the wrapper, for writable paths"],"tags":["java","unsupported-operation","immutability"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}