{"record":{"id":"68869685b2e0bc51","repo":"apache/iceberg","slug":"cannot-update-internalrecordwrapper","errorCode":null,"errorMessage":"Cannot update InternalRecordWrapper","messagePattern":"Cannot update InternalRecordWrapper","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"data/src/main/java/org/apache/iceberg/data/InternalRecordWrapper.java","lineNumber":112,"sourceCode":"  }\n\n  @Override\n  public <T> T get(int pos, Class<T> javaClass) {\n    if (transforms[pos] != null) {\n      Object value = wrapped.get(pos, Object.class);\n      if (value == null) {\n        // transforms function don't allow to handle null values, so just return null here.\n        return null;\n      } else {\n        return javaClass.cast(transforms[pos].apply(value));\n      }\n    }\n    return wrapped.get(pos, javaClass);\n  }\n\n  @Override\n  public <T> void set(int pos, T value) {\n    throw new UnsupportedOperationException(\"Cannot update InternalRecordWrapper\");\n  }\n}\n","sourceCodeStart":94,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/data/src/main/java/org/apache/iceberg/data/InternalRecordWrapper.java#L94-L115","documentation":"InternalRecordWrapper is a read-only StructLike view over another record/wrapper. Its set(int pos, T value) mutator is intentionally unsupported because the wrapper delegates reads but never owns mutable storage. Attempting to write through the wrapper throws UnsupportedOperationException.","triggerScenarios":"Calling set(pos, value) on an InternalRecordWrapper instance — e.g. code treating the wrapper as a writable StructLike when projecting, copying, or writing records through APIs that accept StructLike.","commonSituations":"Passing an InternalRecordWrapper to a writer or data-path that calls StructLike.set; reusing projection wrappers as output records; generic code that both reads and writes StructLike instances.","solutions":["Unwrap and mutate the underlying record instead of the wrapper (access the wrapped object).","Build a new record with the desired values rather than writing through the wrapper.","Use a mutable StructLike (e.g. Record from GenericRecord or InternalRecord) as the write target.","Restructure code so wrappers are used only on the read/projection side."],"exampleFix":"// before\nwrapper.set(2, newValue); // UnsupportedOperationException\n\n// after\nRecord inner = (Record) Data.getDataFromType(wrapper.wrapped());\ninner.set(2, newValue);","handlingStrategy":"type-guard","validationCode":"if (structLike instanceof InternalRecordWrapper) {\n  throw new IllegalArgumentException(\"Wrapper is read-only; mutate the wrapped record instead\");\n}","typeGuard":"StructLike writableTarget(StructLike s) {\n  return (s instanceof InternalRecordWrapper)\n      ? ((InternalRecordWrapper) s).wrapped() instanceof StructLike\n          ? (StructLike) ((InternalRecordWrapper) s).wrapped()\n          : null\n      : s;\n}","tryCatchPattern":"try {\n  struct.set(pos, value);\n} catch (UnsupportedOperationException e) {\n  throw new IllegalStateException(\"Pass a mutable record, not an InternalRecordWrapper\", e);\n}","preventionTips":["Treat InternalRecordWrapper strictly as a read-only projection view.","Only pass mutable records (e.g. GenericData.Record / InternalRecord) to write paths.","Avoid reusing projection wrappers as output containers in generic StructLike code."],"tags":["read-only","structlike","unsupported-operation","record-wrapper"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}