{"record":{"id":"12348bead7f7356b","repo":"apache/iceberg","slug":"cannot-copy-wrapped-datafile","errorCode":null,"errorMessage":"Cannot copy wrapped DataFile","messagePattern":"Cannot copy wrapped DataFile","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/Delegates.java","lineNumber":287,"sourceCode":"\n    @Override\n    public Long dataSequenceNumber() {\n      return wrapped.dataSequenceNumber();\n    }\n\n    @Override\n    public Long fileSequenceNumber() {\n      return wrapped.fileSequenceNumber();\n    }\n\n    @Override\n    public Long firstRowId() {\n      return wrapped.firstRowId();\n    }\n\n    @Override\n    public F copy() {\n      throw new IllegalArgumentException(\"Cannot copy wrapped DataFile\");\n    }\n\n    @Override\n    public F copyWithStats(Set<Integer> requestedColumnIds) {\n      throw new IllegalArgumentException(\"Cannot copy wrapped DataFile\");\n    }\n\n    @Override\n    public F copyWithoutStats() {\n      throw new IllegalArgumentException(\"Cannot copy wrapped DataFile\");\n    }\n  }\n}\n","sourceCodeStart":269,"sourceCodeEnd":301,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/Delegates.java#L269-L301","documentation":"Delegates wraps a DataFile/DeleteFile to override identity-related methods while forwarding everything else to the wrapped file. Copy operations are unsupported on the wrapper because copies must not carry the wrapper semantics, so copy() always throws IllegalArgumentException.","triggerScenarios":"Calling copy() on a DataFile obtained from contexts that return delegated files (e.g. certain index or scan wrappers) instead of an underlying BaseDataFile.","commonSituations":"Generic file-processing code that blindly calls copy() on every DataFile; passing delegated files into utilities that assume copyable concrete files.","solutions":["Unwrap or copy the underlying file rather than the delegate (e.g. use ContentFileUtil.copy on the wrapped file).","Restructure code so copies are made on concrete files before delegation.","If you control the wrapping site, copy before wrapping."],"exampleFix":"// before\nDataFile copy = delegatedFile.copy();\n// after\nDataFile copy = ContentFileUtil.copy(wrapped, false, null);","handlingStrategy":"type-guard","validationCode":"if (file.getClass().getName().contains(\"Delegates$\")) {\n  throw new IllegalStateException(\"copy the wrapped file, not the delegate\");\n}","typeGuard":"boolean isDelegate(ContentFile<?> f) { return f.getClass().getName().contains(\"Delegates$\"); }","tryCatchPattern":"try { copy = file.copy(); } catch (IllegalArgumentException e) {\n  copy = ContentFileUtil.copy(wrapped, false, null);\n}","preventionTips":["Copy files before wrapping them in delegates.","Avoid generic copy() over heterogeneous DataFile collections.","Prefer ContentFileUtil.copy helpers."],"tags":["datafile","copy","unsupported"],"backgroundTag":"operation-not-supported","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"}