Skip to content

Commit 9beb9d7

Browse files
authored
Merge pull request #3991 from spring-cloud/nullability-changes-with-maven-profile-enabled
Fixing NullAway changes
2 parents 8894f36 + 6804d6e commit 9beb9d7

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

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

Lines changed: 5 additions & 5 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(ServiceInstance::getServiceId)
105+
.collectMap(instance -> Objects.requireNonNull(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 String getServiceId() {
185-
if (properties.isLowerCaseServiceId()) {
184+
public @Nullable String getServiceId() {
185+
if (properties.isLowerCaseServiceId() && delegate.getServiceId() != null) {
186186
return delegate.getServiceId().toLowerCase(Locale.ROOT);
187187
}
188188
return delegate.getServiceId();
189189
}
190190

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

@@ -209,7 +209,7 @@ public URI getUri() {
209209
}
210210

211211
@Override
212-
public Map<String, String> getMetadata() {
212+
public @Nullable Map<String, String> getMetadata() {
213213
return delegate.getMetadata();
214214
}
215215

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +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.hasServer()) {
65+
if (serviceInstanceResponse == null || serviceInstanceResponse.getServer() == null) {
66+
return chain.filter(exchange);
67+
}
68+
if (!serviceInstanceResponse.hasServer()) {
6669
return chain.filter(exchange);
6770
}
6871
LoadBalancerProperties properties = loadBalancerClientFactory != null
@@ -78,6 +81,8 @@ public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
7881
}
7982
ServerWebExchange newExchange = exchange.mutate().request(exchange.getRequest().mutate().headers((headers) -> {
8083
List<String> cookieHeaders = new ArrayList<>(headers.getOrEmpty(HttpHeaders.COOKIE));
84+
Objects.requireNonNull(serviceInstanceResponse.getServer(),
85+
"ServiceInstanceResponse.getServer must not be null");
8186
String serviceInstanceCookie = new HttpCookie(instanceIdCookieName,
8287
serviceInstanceResponse.getServer().getInstanceId())
8388
.toString();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import jakarta.servlet.http.Cookie;
2626
import org.apache.commons.logging.Log;
2727
import org.apache.commons.logging.LogFactory;
28+
import org.jspecify.annotations.Nullable;
2829

2930
import org.springframework.cloud.client.ServiceInstance;
3031
import org.springframework.cloud.client.loadbalancer.CompletionContext;
@@ -155,12 +156,12 @@ static class DelegatingServiceInstance implements ServiceInstance {
155156
}
156157

157158
@Override
158-
public String getServiceId() {
159+
public @Nullable String getServiceId() {
159160
return delegate.getServiceId();
160161
}
161162

162163
@Override
163-
public String getHost() {
164+
public @Nullable String getHost() {
164165
return delegate.getHost();
165166
}
166167

@@ -184,7 +185,7 @@ public URI getUri() {
184185
}
185186

186187
@Override
187-
public Map<String, String> getMetadata() {
188+
public @Nullable Map<String, String> getMetadata() {
188189
return delegate.getMetadata();
189190
}
190191

0 commit comments

Comments
 (0)