Fix potential NPE (#320)

* Fix potential NPE

* Fix imports
This commit is contained in:
Georgios Andrianakis
2019-02-04 16:32:10 +02:00
committed by Ryan Baxter
parent fbc53ac44d
commit f9144b1510

View File

@@ -94,7 +94,7 @@ public class KubernetesDiscoveryClient implements DiscoveryClient {
"[Assertion failed] - the object argument must be null");
Endpoints endpoints = client.endpoints().withName(serviceId).get();
List<EndpointSubset> subsets = null != endpoints ? endpoints.getSubsets() : new ArrayList<>();
List<EndpointSubset> subsets = getSubsetsFromEndpoints(endpoints);
List<ServiceInstance> instances = new ArrayList<>();
if (!subsets.isEmpty()) {
@@ -156,6 +156,17 @@ public class KubernetesDiscoveryClient implements DiscoveryClient {
return instances;
}
private List<EndpointSubset> getSubsetsFromEndpoints(Endpoints endpoints) {
if (endpoints == null) {
return new ArrayList<>();
}
if (endpoints.getSubsets() == null) {
return new ArrayList<>();
}
return endpoints.getSubsets();
}
// returns a new map that contain all the entries of the original map
// but with the keys prefixed
// if the prefix is null or empty, the map itself is returned (unchanged of course)