Skip to content

Commit

Permalink
Fix potential NPE (#320)
Browse files Browse the repository at this point in the history
* Fix potential NPE

* Fix imports
  • Loading branch information
geoand authored and Ryan Baxter committed Feb 4, 2019
1 parent fbc53ac commit f9144b1
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<ServiceInstance> getInstances(String serviceId) {
"[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()) {

Expand Down Expand Up @@ -156,6 +156,17 @@ public List<ServiceInstance> getInstances(String serviceId) {
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)
Expand Down

0 comments on commit f9144b1

Please sign in to comment.