Skip to content

Commit e9fab1f

Browse files
authored
GH-10083: Apply Nullability into webflux module
Related to: #10083 Signed-off-by: Jooyoung Pyoung <pyoungjy@gmail.com>
1 parent b06e095 commit e9fab1f

File tree

8 files changed

+23
-12
lines changed

8 files changed

+23
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes for configuration - parsers, namespace handlers.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.webflux.config;

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/dsl/WebFlux.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
import java.net.URI;
2020
import java.util.function.Function;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.expression.Expression;
2325
import org.springframework.integration.expression.FunctionExpression;
2426
import org.springframework.integration.webflux.inbound.WebFluxInboundEndpoint;
25-
import org.springframework.lang.Nullable;
2627
import org.springframework.messaging.Message;
2728
import org.springframework.web.reactive.function.client.WebClient;
2829

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/dsl/WebFluxMessageHandlerSpec.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.net.URI;
2020
import java.util.function.Function;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.core.ParameterizedTypeReference;
2325
import org.springframework.expression.Expression;
2426
import org.springframework.expression.common.LiteralExpression;
@@ -27,7 +29,6 @@
2729
import org.springframework.integration.expression.ValueExpression;
2830
import org.springframework.integration.http.dsl.BaseHttpMessageHandlerSpec;
2931
import org.springframework.integration.webflux.outbound.WebFluxRequestExecutingMessageHandler;
30-
import org.springframework.lang.Nullable;
3132
import org.springframework.messaging.Message;
3233
import org.springframework.web.reactive.function.BodyExtractor;
3334
import org.springframework.web.reactive.function.client.WebClient;
@@ -47,8 +48,7 @@
4748
public class WebFluxMessageHandlerSpec
4849
extends BaseHttpMessageHandlerSpec<WebFluxMessageHandlerSpec, WebFluxRequestExecutingMessageHandler> {
4950

50-
@Nullable
51-
protected final WebClient webClient; // NOSONAR - final
51+
protected final @Nullable WebClient webClient;
5252

5353
protected WebFluxMessageHandlerSpec(URI uri, @Nullable WebClient webClient) {
5454
this(new ValueExpression<>(uri), webClient);
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Provides WebFlux Components support for Spring Integration Java DSL.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@org.jspecify.annotations.NullMarked
65
package org.springframework.integration.webflux.dsl;

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxInboundEndpoint.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.function.Supplier;
2828
import java.util.stream.Collectors;
2929

30+
import org.jspecify.annotations.Nullable;
3031
import org.reactivestreams.Publisher;
3132
import reactor.core.publisher.Flux;
3233
import reactor.core.publisher.Mono;
@@ -458,7 +459,7 @@ private List<MediaType> getProducibleMediaTypes(ResolvableType elementType) {
458459
.collect(Collectors.toList());
459460
}
460461

461-
private MediaType selectMediaType(ServerWebExchange exchange, Supplier<List<MediaType>> producibleTypesSupplier) {
462+
private @Nullable MediaType selectMediaType(ServerWebExchange exchange, Supplier<List<MediaType>> producibleTypesSupplier) {
462463
List<MediaType> acceptableTypes = getAcceptableTypes(exchange);
463464
List<MediaType> producibleTypes = getProducibleTypes(exchange, producibleTypesSupplier);
464465

spring-integration-webflux/src/main/java/org/springframework/integration/webflux/inbound/WebFluxIntegrationRequestMappingHandlerMapping.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.List;
2222
import java.util.concurrent.atomic.AtomicBoolean;
2323

24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.beans.BeansException;
2527
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;
2628
import org.springframework.context.ApplicationListener;
@@ -86,6 +88,7 @@
8688
public class WebFluxIntegrationRequestMappingHandlerMapping extends RequestMappingHandlerMapping
8789
implements ApplicationListener<ContextRefreshedEvent>, DestructionAwareBeanPostProcessor {
8890

91+
@SuppressWarnings("NullAway") // Reflection
8992
private static final Method HANDLER_METHOD =
9093
ReflectionUtils.findMethod(WebHandler.class, "handle", ServerWebExchange.class);
9194

@@ -103,7 +106,10 @@ public Object postProcessBeforeInitialization(Object bean, String beanName) thro
103106
@Override
104107
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
105108
if (isHandler(bean.getClass())) {
106-
unregisterMapping(getMappingForEndpoint((WebFluxInboundEndpoint) bean));
109+
RequestMappingInfo mapping = getMappingForEndpoint((WebFluxInboundEndpoint) bean);
110+
if (mapping != null) {
111+
unregisterMapping(mapping);
112+
}
107113
}
108114
}
109115

@@ -118,13 +124,14 @@ protected boolean isHandler(Class<?> beanType) {
118124
}
119125

120126
@Override
127+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
121128
protected void detectHandlerMethods(Object handler) {
122129
if (handler instanceof String string) {
123-
handler = getApplicationContext().getBean(string); // NOSONAR never null
130+
handler = getApplicationContext().getBean(string);
124131
}
125132
RequestMappingInfo mapping = getMappingForEndpoint((WebFluxInboundEndpoint) handler);
126133
if (mapping != null) {
127-
registerMapping(mapping, handler, HANDLER_METHOD); // NOSONAR never null
134+
registerMapping(mapping, handler, HANDLER_METHOD);
128135
}
129136
}
130137

@@ -134,7 +141,7 @@ protected void detectHandlerMethods(Object handler) {
134141
* {@link org.springframework.integration.http.inbound.RequestMapping}.
135142
* @see RequestMappingHandlerMapping#getMappingForMethod
136143
*/
137-
private RequestMappingInfo getMappingForEndpoint(WebFluxInboundEndpoint endpoint) {
144+
private @Nullable RequestMappingInfo getMappingForEndpoint(WebFluxInboundEndpoint endpoint) {
138145
org.springframework.web.bind.annotation.RequestMapping requestMappingAnnotation =
139146
HttpContextUtils.convertRequestMappingToAnnotation(endpoint.getRequestMapping());
140147
if (requestMappingAnnotation != null) {
@@ -146,7 +153,7 @@ private RequestMappingInfo getMappingForEndpoint(WebFluxInboundEndpoint endpoint
146153
}
147154

148155
@Override
149-
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
156+
protected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
150157
CrossOrigin crossOrigin = ((BaseHttpInboundEndpoint) handler).getCrossOrigin();
151158
if (crossOrigin != null) {
152159
return buildCorsConfiguration(crossOrigin, mappingInfo);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes supporting inbound endpoints.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.webflux.inbound;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes to support WebFlux endpoints.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.webflux.support;

0 commit comments

Comments
 (0)