Skip to content

Commit f9144b1

Browse files
geoandRyan Baxter
authored andcommitted
Fix potential NPE (#320)
* Fix potential NPE * Fix imports
1 parent fbc53ac commit f9144b1

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

spring-cloud-kubernetes-discovery/src/main/java/org/springframework/cloud/kubernetes/discovery/KubernetesDiscoveryClient.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public List<ServiceInstance> getInstances(String serviceId) {
9494
"[Assertion failed] - the object argument must be null");
9595

9696
Endpoints endpoints = client.endpoints().withName(serviceId).get();
97-
List<EndpointSubset> subsets = null != endpoints ? endpoints.getSubsets() : new ArrayList<>();
97+
List<EndpointSubset> subsets = getSubsetsFromEndpoints(endpoints);
9898
List<ServiceInstance> instances = new ArrayList<>();
9999
if (!subsets.isEmpty()) {
100100

@@ -156,6 +156,17 @@ public List<ServiceInstance> getInstances(String serviceId) {
156156
return instances;
157157
}
158158

159+
private List<EndpointSubset> getSubsetsFromEndpoints(Endpoints endpoints) {
160+
if (endpoints == null) {
161+
return new ArrayList<>();
162+
}
163+
if (endpoints.getSubsets() == null) {
164+
return new ArrayList<>();
165+
}
166+
167+
return endpoints.getSubsets();
168+
}
169+
159170
// returns a new map that contain all the entries of the original map
160171
// but with the keys prefixed
161172
// if the prefix is null or empty, the map itself is returned (unchanged of course)

0 commit comments

Comments
 (0)