{"record":{"id":"12399de0daba5fbc","repo":"apache/iceberg","slug":"unexpected-entry-status-not-added-or-deleted-s","errorCode":null,"errorMessage":"Unexpected entry status, not added or deleted: %s","messagePattern":"Unexpected entry status, not added or deleted: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/BaseSnapshot.java","lineNumber":319,"sourceCode":"    ImmutableList.Builder<DataFile> adds = ImmutableList.builder();\n    ImmutableList.Builder<DataFile> deletes = ImmutableList.builder();\n\n    // read only manifests that were created by this snapshot\n    Iterable<ManifestFile> changedManifests =\n        Iterables.filter(\n            dataManifests(fileIO), manifest -> Objects.equal(manifest.snapshotId(), snapshotId));\n    try (CloseableIterable<ManifestEntry<DataFile>> entries =\n        new ManifestGroup(fileIO, changedManifests).ignoreExisting().entries()) {\n      for (ManifestEntry<DataFile> entry : entries) {\n        switch (entry.status()) {\n          case ADDED:\n            adds.add(entry.file().copy());\n            break;\n          case DELETED:\n            deletes.add(entry.file().copyWithoutStats());\n            break;\n          default:\n            throw new IllegalStateException(\n                \"Unexpected entry status, not added or deleted: \" + entry);\n        }\n      }\n    } catch (IOException e) {\n      throw new RuntimeIOException(e, \"Failed to close entries while caching changes\");\n    }\n\n    this.addedDataFiles = adds.build();\n    this.removedDataFiles = deletes.build();\n  }\n\n  @Override\n  public boolean equals(Object o) {\n    if (this == o) {\n      return true;\n    }\n\n    if (o instanceof BaseSnapshot) {","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/BaseSnapshot.java#L301-L337","documentation":"When caching data-file changes, BaseSnapshot expects each manifest entry status to be ADDED or DELETED; any other status (e.g. EXISTING) hits the default branch and throws IllegalStateException. This guards a broken invariant: change-caching scans only v1 manifests where added/removed changes are representable, so other statuses indicate corrupt or unexpected data.","triggerScenarios":"Calling addedDataFiles()/removedDataFiles() on a snapshot whose manifests contain entries with EXISTING status — e.g. snapshots produced by operations that copied entries, or a corrupt manifest list pointing to the wrong (non-delta) manifest.","commonSituations":"Hand-built or migrated metadata; reading v1 tables with tooling that mislabeled manifests; a bug in a custom snapshot producer that emits existing entries where deltas are expected.","solutions":["Verify the snapshot's manifests come from a valid append/overwrite snapshot (operations().current().currentSnapshot().snapshotId())","Rebuild/repair table metadata if manifests are corrupt (e.g. from a metadata backup or add_files procedure)","Upgrade Iceberg if the producing operation was from an older buggy version","Don't call addedDataFiles/removedDataFiles on snapshots (e.g. overflow/rollback) that don't represent direct file changes"],"exampleFix":"// before: uses arbitrary snapshot id\nSnapshot s = table.snapshot(someOldSnapshotId);\ns.addedDataFiles();\n// after: only direct-change snapshots\nSnapshot s = table.currentSnapshot();\nif (s.operation().equals(DataOperations.APPEND) || s.operation().equals(DataOperations.OVERWRITE)) {\n  s.addedDataFiles();\n}","handlingStrategy":"validation","validationCode":"if (!Set.of(DataOperations.APPEND, DataOperations.OVERWRITE).contains(snapshot.operation())) {\n  throw new IllegalStateException(\"addedDataFiles only valid for append/overwrite snapshots\");\n}","typeGuard":"boolean isDeltaSnapshot(Snapshot s) { return DataOperations.APPEND.equals(s.operation()) || DataOperations.OVERWRITE.equals(s.operation()); }","tryCatchPattern":"try { snapshot.addedDataFiles(); } catch (IllegalStateException e) { /* fall back to full manifest diff */ }","preventionTips":["Only call added/removedDataFiles on snapshots that represent direct file changes","Verify manifest entry statuses when producing snapshots in custom producers","Repair corrupt metadata from backups rather than forcing reads"],"tags":["iceberg","manifest-entry","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}