Make Noderesolver robust against null values (#62893)
make node resolving more robust by ignoring null values. This is a bug in the usage of this class, however you don't want NPE's in prod. The root cause might be a corner case. Because silencing the root cause is bad, the assert causes a fail if assertions are enabled relates #62847
This commit is contained in:
parent
ef7a6ce4b2
commit
4d43fa8816
|
@ -338,7 +338,11 @@ public class DiscoveryNodes extends AbstractDiffable<DiscoveryNodes> implements
|
|||
} else {
|
||||
ObjectHashSet<String> 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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue