This is an automated email from the ASF dual-hosted git repository.
pvary pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new 2d6bf3a0f6 Core: Fix NPE in SnapshotUtil.snapshotAfter for
non-ancestor snapshots (#18908)
2d6bf3a0f6 is described below
commit 2d6bf3a0f61f4ee4a71fc7447d66fdae41151cf5
Author: chenjian2664 <[email protected]>
AuthorDate: Mon Nov 23 16:05:02 2026 +0800
Core: Fix NPE in SnapshotUtil.snapshotAfter for non-ancestor snapshots
(#18908)
---
core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java | 2 +-
core/src/test/java/org/apache/iceberg/util/TestSnapshotUtil.java | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
b/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
index 6ba655666b..62bd048cf7 100644
--- a/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
+++ b/core/src/main/java/org/apache/iceberg/util/SnapshotUtil.java
@@ -291,7 +291,7 @@ public class SnapshotUtil {
Preconditions.checkArgument(
table.snapshot(snapshotId) != null, "Cannot find parent snapshot: %s",
snapshotId);
for (Snapshot current : currentAncestors(table)) {
- if (current.parentId() == snapshotId) {
+ if (current.parentId() != null && current.parentId() == snapshotId) {
return current;
}
}
diff --git a/core/src/test/java/org/apache/iceberg/util/TestSnapshotUtil.java
b/core/src/test/java/org/apache/iceberg/util/TestSnapshotUtil.java
index 12a6936e73..5b44d29c4e 100644
--- a/core/src/test/java/org/apache/iceberg/util/TestSnapshotUtil.java
+++ b/core/src/test/java/org/apache/iceberg/util/TestSnapshotUtil.java
@@ -185,6 +185,15 @@ public class TestSnapshotUtil {
assertThat(snapshotIter).isExhausted();
}
+ @Test
+ void snapshotAfterNonAncestor() {
+ assertThatThrownBy(() -> SnapshotUtil.snapshotAfter(table,
snapshotBranchId))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(
+ "Cannot find snapshot after %s: not an ancestor of table's current
snapshot",
+ snapshotBranchId);
+ }
+
private void expectedSnapshots(long[] snapshotIdExpected, Iterable<Snapshot>
snapshotsActual) {
long[] actualSnapshots =
StreamSupport.stream(snapshotsActual.spliterator(), false)