diff --git a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java index 6f8f680b10a..58e7f3408b4 100644 --- a/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java +++ b/server/src/main/java/org/elasticsearch/cluster/node/DiscoveryNodes.java @@ -338,7 +338,11 @@ public class DiscoveryNodes extends AbstractDiffable implements } else { ObjectHashSet resolvedNodesIds = new ObjectHashSet<>(nodes.length); for (String nodeId : nodes) { - if (nodeId.equals("_local")) { + if (nodeId == null) { + // don't silence the underlying issue, it is a bug, so lets fail if assertions are enabled + assert nodeId != null : "nodeId should not be null"; + continue; + } else if (nodeId.equals("_local")) { String localNodeId = getLocalNodeId(); if (localNodeId != null) { resolvedNodesIds.add(localNodeId); diff --git a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java index 14da84d4971..8ba1ac84666 100644 --- a/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/node/DiscoveryNodesTests.java @@ -75,6 +75,15 @@ public class DiscoveryNodesTests extends ESTestCase { } } + public void testResolveNodesNull() { + DiscoveryNodes discoveryNodes = buildDiscoveryNodes(); + + // if assertions are enabled (should be the case for tests, but not in production), resolving null throws + expectThrows(AssertionError.class, () -> discoveryNodes.resolveNodes(Collections.singletonList(null).toArray(new String[0]))); + expectThrows(AssertionError.class, () -> discoveryNodes.resolveNodes(null, "someNode")); + expectThrows(AssertionError.class, () -> discoveryNodes.resolveNodes("someNode", null, "someOtherNode")); + } + public void testAll() { final DiscoveryNodes discoveryNodes = buildDiscoveryNodes();