{"record":{"id":"fa4ca39a5c47c910","repo":"apache/iceberg","slug":"cannot-apply-update-s-to-a-table","errorCode":null,"errorMessage":"Cannot apply update %s to a table","messagePattern":"Cannot apply update (.+?) to a table","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/MetadataUpdate.java","lineNumber":33,"sourceCode":" * KIND, either express or implied.  See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.iceberg;\n\nimport java.io.Serializable;\nimport java.util.Locale;\nimport java.util.Map;\nimport java.util.Set;\nimport org.apache.iceberg.encryption.EncryptedKey;\nimport org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet;\nimport org.apache.iceberg.view.ViewMetadata;\nimport org.apache.iceberg.view.ViewVersion;\n\n/** Represents a change to table or view metadata. */\npublic interface MetadataUpdate extends Serializable {\n  default void applyTo(TableMetadata.Builder metadataBuilder) {\n    throw new UnsupportedOperationException(\n        String.format(\"Cannot apply update %s to a table\", this.getClass().getSimpleName()));\n  }\n\n  default void applyTo(ViewMetadata.Builder viewMetadataBuilder) {\n    throw new UnsupportedOperationException(\n        String.format(\"Cannot apply update %s to a view\", this.getClass().getSimpleName()));\n  }\n\n  class AssignUUID implements MetadataUpdate {\n    private final String uuid;\n\n    public AssignUUID(String uuid) {\n      this.uuid = uuid;\n    }\n\n    public String uuid() {\n      return uuid;\n    }","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/MetadataUpdate.java#L15-L51","documentation":"UnsupportedOperationException thrown by the default MetadataUpdate.applyTo methods when an update implementation does not support applying to table (or view) metadata. Each MetadataUpdate subclass overrides the applyTo relevant to its target; calling the other variant — or a custom update that overrides neither — reaches the default throw. It signals applying an update to the wrong metadata type.","triggerScenarios":"Calling MetadataUpdate.applyTo(TableMetadata.Builder) with an update class that only supports views (e.g., AssignUUID for views path, or view-specific updates) or a custom/unknown implementation that overrides neither method.","commonSituations":"Custom catalog code replaying a mixed list of table and view updates against one builder; REST metadata processing where update objects are applied to the wrong builder; adding a new MetadataUpdate subclass without overriding applyTo.","solutions":["Apply table-targeted updates only to TableMetadata.Builder and view-targeted updates only to ViewMetadata.Builder; filter the update list by update class.","If implementing a new MetadataUpdate, override the appropriate applyTo method.","Check update compatibility before applying (e.g., instanceof ViewUpdate vs table update).","If replaying REST metadata changes, split updates into table and view lists by class before applying."],"exampleFix":"// before\nfor (MetadataUpdate update : updates) {\n  update.applyTo(tableBuilder); // throws for view-only updates\n}\n// after\nfor (MetadataUpdate update : updates) {\n  if (!(update instanceof ViewUpdate)) {\n    update.applyTo(tableBuilder);\n  }\n}","handlingStrategy":"type-guard","validationCode":"// split updates by target before applying\nList<MetadataUpdate> tableUpdates = updates.stream().filter(u -> !(u instanceof ViewUpdate)).toList();","typeGuard":"boolean isTableUpdate(MetadataUpdate u) { return !(u instanceof ViewUpdate); }","tryCatchPattern":"try {\n  update.applyTo(tableBuilder);\n} catch (UnsupportedOperationException e) {\n  // update targets views; apply to ViewMetadata.Builder instead\n}","preventionTips":["Only apply table updates to TableMetadata.Builder and view updates to ViewMetadata.Builder","Override the correct applyTo when implementing new MetadataUpdate types","Filter mixed update lists by class before replaying"],"tags":["unsupported-operation","metadata-update","api-misuse"],"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"}