Fix NullPointerException in MockUncasedHostProvider (#28424)

The MockUncasedHostProvider accesses nodes that are not fully built yet, where TransportService.getNode() returns null, which means that the null entries end up in the list of seedNodes that UnicastZenPing then uses.
This commit is contained in:
Yannick Welsch 2018-01-30 10:44:19 +01:00 committed by GitHub
parent f5f679f921
commit 9dd0886265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -20,6 +20,7 @@ package org.elasticsearch.test.discovery;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.discovery.zen.UnicastHostsProvider;
@ -27,6 +28,7 @@ import java.io.Closeable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
@ -54,15 +56,19 @@ public final class MockUncasedHostProvider implements UnicastHostsProvider, Clos
@Override
public List<DiscoveryNode> buildDynamicNodes() {
final DiscoveryNode localNode = getNode();
assert localNode != null;
synchronized (activeNodesPerCluster) {
Set<MockUncasedHostProvider> activeNodes = getActiveNodesForCurrentCluster();
return activeNodes.stream()
.map(MockUncasedHostProvider::getNode)
.filter(n -> !localNodeSupplier.get().equals(n))
.filter(Objects::nonNull)
.filter(n -> localNode.equals(n) == false)
.collect(Collectors.toList());
}
}
@Nullable
private DiscoveryNode getNode() {
return localNodeSupplier.get();
}