From 4b61d9a5ef5d3ad637bb5f92b5d946728edc6f23 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Fri, 20 Aug 2021 16:09:40 -0600 Subject: [PATCH] Fix NPE in NodeSeenService (#76788) This commit adjusts `NodeSeenService` to check if the `NodesShutdownMetadata` is `null` before trying to work with it. If it is `null`, we can simply return from the method early as we know there are no shutdowns registered. --- .../org/elasticsearch/xpack/shutdown/NodeSeenService.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/NodeSeenService.java b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/NodeSeenService.java index 3bf3a846a8a27..c3aba27cf5f5f 100644 --- a/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/NodeSeenService.java +++ b/x-pack/plugin/shutdown/src/main/java/org/elasticsearch/xpack/shutdown/NodeSeenService.java @@ -52,6 +52,12 @@ public void clusterChanged(ClusterChangedEvent event) { } NodesShutdownMetadata eventShutdownMetadata = event.state().metadata().custom(NodesShutdownMetadata.TYPE); + + if (eventShutdownMetadata == null) { + // Since there's no shutdown metadata at all, we know no shutdowns have ever been registered and we can bail. + return; + } + final Set nodesNotPreviouslySeen = eventShutdownMetadata.getAllNodeMetadataMap() .values() .stream()