From f24cb6bf633707a86b492195f895a96cdb29a119 Mon Sep 17 00:00:00 2001 From: Gordon Brown Date: Fri, 20 Aug 2021 17:25:41 -0600 Subject: [PATCH] Fix NPE in NodeSeenService (#76788) (#76795) 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()