From 1114d7645da1f4a1f3ac5711e30416b236c73602 Mon Sep 17 00:00:00 2001 From: Przemko Robakowski Date: Tue, 10 Mar 2020 19:36:23 +0100 Subject: [PATCH] Fix null config in SnapshotLifecyclePolicy.toRequest (#53328) This avoids NPE when executing SLM policy when no config was provided. Related to #44465 Closes #53171 Co-authored-by: Elastic Machine --- .../xpack/core/slm/SnapshotLifecyclePolicy.java | 4 ++-- .../xpack/slm/SnapshotLifecyclePolicyTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecyclePolicy.java index 0ef7912c58017..0d7ab44ed9582 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecyclePolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/SnapshotLifecyclePolicy.java @@ -254,10 +254,10 @@ public String generateSnapshotName(Context context) { */ public CreateSnapshotRequest toRequest() { CreateSnapshotRequest req = new CreateSnapshotRequest(repository, generateSnapshotName(new ResolverContext())); + Map mergedConfiguration = configuration == null ? new HashMap<>() : new HashMap<>(configuration); @SuppressWarnings("unchecked") - Map metadata = (Map) configuration.get("metadata"); + Map metadata = (Map) mergedConfiguration.get("metadata"); Map metadataWithAddedPolicyName = addPolicyNameToMetadata(metadata); - Map mergedConfiguration = new HashMap<>(configuration); mergedConfiguration.put("metadata", metadataWithAddedPolicyName); req.source(mergedConfiguration); req.waitForCompletion(true); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecyclePolicyTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecyclePolicyTests.java index 6523d7a07228a..b3149cc177e5a 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecyclePolicyTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecyclePolicyTests.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.slm; +import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; import org.elasticsearch.common.ValidationException; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.XContentParser; @@ -30,6 +31,18 @@ public class SnapshotLifecyclePolicyTests extends AbstractSerializingTestCase