From e1862b60d2b5846117df47b54a9c698d8035f1e9 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 13 Aug 2021 17:34:09 +0200 Subject: [PATCH] Fix Mutable Data Structure in SnapshotsInProgress The feature info instances shouldn't be mutable to prevent accidental bugs down the line. --- .../java/org/elasticsearch/cluster/SnapshotsInProgress.java | 2 +- .../org/elasticsearch/snapshots/SnapshotFeatureInfo.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java b/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java index 37e8715b02894..947ca3acde233 100644 --- a/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java +++ b/server/src/main/java/org/elasticsearch/cluster/SnapshotsInProgress.java @@ -547,7 +547,7 @@ private Entry(Snapshot snapshot, boolean includeGlobalState, boolean partial, St this.partial = partial; this.indices = Map.copyOf(indices); this.dataStreams = List.copyOf(dataStreams); - this.featureStates = Collections.unmodifiableList(featureStates); + this.featureStates = List.copyOf(featureStates); this.startTime = startTime; this.shards = shards; this.repositoryStateId = repositoryStateId; diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotFeatureInfo.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotFeatureInfo.java index 5278e041023b6..d5daac995001f 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotFeatureInfo.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotFeatureInfo.java @@ -44,12 +44,11 @@ public class SnapshotFeatureInfo implements Writeable, ToXContentObject { public SnapshotFeatureInfo(String pluginName, List indices) { this.pluginName = pluginName; - this.indices = indices; + this.indices = List.copyOf(indices); } public SnapshotFeatureInfo(final StreamInput in) throws IOException { - this.pluginName = in.readString(); - this.indices = in.readStringList(); + this(in.readString(), in.readStringList()); } @Override