Skip to content

Commit a8e87f8

Browse files
committed
Updates for nullabilty in ServiceInstance
See spring-cloud/spring-cloud-commons#1604
1 parent 9beb9d7 commit a8e87f8

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/discovery/DiscoveryClientRouteDefinitionLocator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public Flux<RouteDefinition> getRouteDefinitions() {
102102
return serviceInstances.filter(instances -> !instances.isEmpty())
103103
.flatMap(Flux::fromIterable)
104104
.filter(includePredicate)
105-
.collectMap(instance -> Objects.requireNonNull(instance.getServiceId()))
105+
.collectMap(instance -> instance.getServiceId())
106106
// remove duplicates
107107
.flatMapMany(map -> Flux.fromIterable(map.values()))
108108
.map(instance -> {
@@ -181,15 +181,15 @@ private DelegatingServiceInstance(ServiceInstance delegate, DiscoveryLocatorProp
181181
}
182182

183183
@Override
184-
public @Nullable String getServiceId() {
185-
if (properties.isLowerCaseServiceId() && delegate.getServiceId() != null) {
184+
public String getServiceId() {
185+
if (properties.isLowerCaseServiceId()) {
186186
return delegate.getServiceId().toLowerCase(Locale.ROOT);
187187
}
188188
return delegate.getServiceId();
189189
}
190190

191191
@Override
192-
public @Nullable String getHost() {
192+
public String getHost() {
193193
return delegate.getHost();
194194
}
195195

spring-cloud-gateway-server-webflux/src/main/java/org/springframework/cloud/gateway/filter/LoadBalancerServiceInstanceCookieFilter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@ public LoadBalancerServiceInstanceCookieFilter(
6262
@Override
6363
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
6464
Response<ServiceInstance> serviceInstanceResponse = exchange.getAttribute(GATEWAY_LOADBALANCER_RESPONSE_ATTR);
65-
if (serviceInstanceResponse == null || serviceInstanceResponse.getServer() == null) {
66-
return chain.filter(exchange);
67-
}
68-
if (!serviceInstanceResponse.hasServer()) {
65+
if (serviceInstanceResponse == null || !serviceInstanceResponse.hasServer()) {
6966
return chain.filter(exchange);
7067
}
68+
@SuppressWarnings("NullAway") // protected by hasServer() above
7169
LoadBalancerProperties properties = loadBalancerClientFactory != null
7270
? loadBalancerClientFactory.getProperties(serviceInstanceResponse.getServer().getServiceId())
7371
: loadBalancerProperties;

spring-cloud-gateway-server-webmvc/src/main/java/org/springframework/cloud/gateway/server/mvc/filter/LoadBalancerFilterFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ static class DelegatingServiceInstance implements ServiceInstance {
156156
}
157157

158158
@Override
159-
public @Nullable String getServiceId() {
159+
public String getServiceId() {
160160
return delegate.getServiceId();
161161
}
162162

163163
@Override
164-
public @Nullable String getHost() {
164+
public String getHost() {
165165
return delegate.getHost();
166166
}
167167

0 commit comments

Comments
 (0)