From 1f6a3765e46f904270a0f1862aaae37ca5a4960c Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Wed, 29 Jul 2020 10:47:28 +0200 Subject: [PATCH] Fix NPE in SnapshotsInProgress Constructor (#60355) Merge oversight between cleanups that removed `null` for `shards` and this corner case spot of no indices in a snapshot. Closes #60330 --- .../snapshots/DedicatedClusterSnapshotRestoreIT.java | 5 +++++ .../java/org/elasticsearch/snapshots/SnapshotsService.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index df7dfd37b7c..7b30a51c7c2 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -1303,6 +1303,11 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest final SnapshotInfo snapshot2 = PlainActionFuture.get(f -> snapshotsService.executeSnapshotLegacy(new CreateSnapshotRequest(repoName, "snap-2"), f)); assertThat(snapshot2.state(), is(SnapshotState.SUCCESS)); + + final SnapshotInfo snapshot3 = + PlainActionFuture.get(f -> snapshotsService.executeSnapshotLegacy( + new CreateSnapshotRequest(repoName, "snap-3").indices("does-not-exist-*"), f)); + assertThat(snapshot3.state(), is(SnapshotState.SUCCESS)); } private long calculateTotalFilesSize(List files) { diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index a30fb8b70b4..8313109ce86 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -565,7 +565,7 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus // No indices in this snapshot - we are done userCreateSnapshotListener.onResponse(snapshot.snapshot()); endSnapshot(new SnapshotsInProgress.Entry( - snapshot, State.STARTED, Collections.emptyList(), repositoryData.getGenId(), null, version, + snapshot, State.STARTED, Collections.emptyList(), repositoryData.getGenId(), ImmutableOpenMap.of(), version, null), clusterState.metadata(), repositoryData); return; }