Skip to content

Commit 3df47ea

Browse files
GH-10083: Apply NullAbility to rsocket module
Related to: #10083 * Remove `@Nullable` * Revert `@Nullable` in `RSocketOutboundGateway#RSocketRequester` * Change to private ctor Signed-off-by: Tran Ngoc Nhan <[email protected]>
1 parent a409fee commit 3df47ea

File tree

13 files changed

+78
-66
lines changed

13 files changed

+78
-66
lines changed

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/AbstractRSocketConnector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616

1717
package org.springframework.integration.rsocket;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.beans.BeansException;
2022
import org.springframework.beans.factory.DisposableBean;
2123
import org.springframework.beans.factory.InitializingBean;
2224
import org.springframework.beans.factory.SmartInitializingSingleton;
2325
import org.springframework.context.ApplicationContext;
2426
import org.springframework.context.ApplicationContextAware;
2527
import org.springframework.context.SmartLifecycle;
26-
import org.springframework.lang.Nullable;
2728
import org.springframework.messaging.rsocket.RSocketStrategies;
2829
import org.springframework.util.Assert;
2930
import org.springframework.util.MimeType;
@@ -64,8 +65,7 @@ public void setDataMimeType(@Nullable MimeType dataMimeType) {
6465
this.rSocketMessageHandler.setDefaultDataMimeType(dataMimeType);
6566
}
6667

67-
@Nullable
68-
protected MimeType getDataMimeType() {
68+
protected @Nullable MimeType getDataMimeType() {
6969
return this.rSocketMessageHandler.getDefaultDataMimeType();
7070
}
7171

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ClientRSocketConnector.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,17 @@ public class ClientRSocketConnector extends AbstractRSocketConnector {
4949
private RSocketConnectorConfigurer connectorConfigurer = (connector) -> {
5050
};
5151

52+
@SuppressWarnings("NullAway.Init")
5253
private Object setupData;
5354

55+
@SuppressWarnings("NullAway.Init")
5456
private String setupRoute;
5557

5658
private Object[] setupRouteVars = new Object[0];
5759

5860
private boolean autoConnect;
5961

62+
@SuppressWarnings("NullAway.Init")
6063
private RSocketRequester rsocketRequester;
6164

6265
/**

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/IntegrationRSocketMessageHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626

2727
import io.rsocket.Payload;
2828
import io.rsocket.frame.FrameType;
29+
import org.jspecify.annotations.Nullable;
2930
import reactor.core.publisher.Flux;
3031
import reactor.core.publisher.Mono;
3132

3233
import org.springframework.context.ApplicationContext;
3334
import org.springframework.core.MethodParameter;
3435
import org.springframework.core.ReactiveAdapterRegistry;
3536
import org.springframework.core.codec.Encoder;
36-
import org.springframework.lang.Nullable;
3737
import org.springframework.messaging.Message;
3838
import org.springframework.messaging.ReactiveMessageHandler;
3939
import org.springframework.messaging.handler.CompositeMessageCondition;
@@ -60,6 +60,7 @@
6060
*/
6161
class IntegrationRSocketMessageHandler extends RSocketMessageHandler {
6262

63+
@SuppressWarnings("NullAway") // Reflection
6364
private static final Method HANDLE_MESSAGE_METHOD =
6465
ReflectionUtils.findMethod(ReactiveMessageHandler.class, "handleMessage", Message.class);
6566

@@ -105,7 +106,7 @@ public void addEndpoint(IntegrationRSocketEndpoint endpoint) {
105106
registerHandlerMethod(endpoint, HANDLE_MESSAGE_METHOD,
106107
new CompositeMessageCondition(
107108
frameTypeMessageCondition,
108-
new DestinationPatternsMessageCondition(endpoint.getPath(), getRouteMatcher()))); // NOSONAR
109+
new DestinationPatternsMessageCondition(endpoint.getPath(), obtainRouteMatcher()))); // NOSONAR
109110
}
110111

111112
@Override
@@ -173,9 +174,8 @@ public Mono<Void> handleReturnValue(@Nullable Object returnValue, MethodParamete
173174
}
174175
}
175176

176-
@Nullable
177177
@SuppressWarnings("unchecked")
178-
private static AtomicReference<Flux<Payload>> getResponseReference(Message<?> message) {
178+
private static @Nullable AtomicReference<Flux<Payload>> getResponseReference(Message<?> message) {
179179
Object headerValue = message.getHeaders().get(RESPONSE_HEADER);
180180
Assert.state(headerValue == null || headerValue instanceof AtomicReference, "Expected AtomicReference");
181181
return (AtomicReference<Flux<Payload>>) headerValue;

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketConnector.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.rsocket.transport.netty.server.CloseableChannel;
2626
import io.rsocket.transport.netty.server.TcpServerTransport;
2727
import io.rsocket.transport.netty.server.WebsocketServerTransport;
28+
import org.jspecify.annotations.Nullable;
2829
import reactor.core.Disposable;
2930
import reactor.core.publisher.Mono;
3031
import reactor.netty.http.server.HttpServer;
@@ -34,7 +35,6 @@
3435
import org.springframework.context.ApplicationEventPublisher;
3536
import org.springframework.context.ApplicationEventPublisherAware;
3637
import org.springframework.core.io.buffer.DataBuffer;
37-
import org.springframework.lang.Nullable;
3838
import org.springframework.messaging.rsocket.RSocketRequester;
3939
import org.springframework.messaging.rsocket.RSocketStrategies;
4040
import org.springframework.util.Assert;
@@ -51,11 +51,12 @@
5151
*/
5252
public class ServerRSocketConnector extends AbstractRSocketConnector implements ApplicationEventPublisherAware {
5353

54-
private final ServerTransport<CloseableChannel> serverTransport;
54+
private final @Nullable ServerTransport<CloseableChannel> serverTransport;
5555

5656
private Consumer<RSocketServer> serverConfigurer = (rsocketServer) -> {
5757
};
5858

59+
@SuppressWarnings("NullAway.Init")
5960
private Mono<CloseableChannel> serverMono;
6061

6162
/**
@@ -191,8 +192,7 @@ public Map<Object, RSocketRequester> getClientRSocketRequesters() {
191192
* @return the {@link RSocketRequester} or null.
192193
* @see ServerRSocketMessageHandler#getClientRSocketRequester(Object)
193194
*/
194-
@Nullable
195-
public RSocketRequester getClientRSocketRequester(Object key) {
195+
public @Nullable RSocketRequester getClientRSocketRequester(Object key) {
196196
return serverRSocketMessageHandler().getClientRSocketRequester(key);
197197
}
198198

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/ServerRSocketMessageHandler.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
import java.util.Map;
2424
import java.util.function.BiFunction;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.aot.hint.annotation.Reflective;
2729
import org.springframework.context.ApplicationEventPublisher;
2830
import org.springframework.context.ApplicationEventPublisherAware;
2931
import org.springframework.core.io.buffer.DataBuffer;
30-
import org.springframework.lang.Nullable;
3132
import org.springframework.messaging.Message;
3233
import org.springframework.messaging.MessageHeaders;
3334
import org.springframework.messaging.handler.CompositeMessageCondition;
@@ -60,6 +61,7 @@
6061
public class ServerRSocketMessageHandler extends IntegrationRSocketMessageHandler
6162
implements ApplicationEventPublisherAware {
6263

64+
@SuppressWarnings("NullAway") // Reflection
6365
private static final Method HANDLE_CONNECTION_SETUP_METHOD =
6466
ReflectionUtils.findMethod(ServerRSocketMessageHandler.class, "handleConnectionSetup", Message.class);
6567

@@ -68,7 +70,7 @@ public class ServerRSocketMessageHandler extends IntegrationRSocketMessageHandle
6870
private BiFunction<Map<String, Object>, DataBuffer, Object> clientRSocketKeyStrategy =
6971
(headers, data) -> data.toString(StandardCharsets.UTF_8);
7072

71-
private ApplicationEventPublisher applicationEventPublisher;
73+
private @Nullable ApplicationEventPublisher applicationEventPublisher;
7274

7375
/**
7476
* Create an service side RSocket message handler instance for delegating
@@ -120,8 +122,7 @@ public Map<Object, RSocketRequester> getClientRSocketRequesters() {
120122
* @param key the key for mapped {@link RSocketRequester} if any.
121123
* @return the mapped {@link RSocketRequester} or null.
122124
*/
123-
@Nullable
124-
public RSocketRequester getClientRSocketRequester(Object key) {
125+
public @Nullable RSocketRequester getClientRSocketRequester(Object key) {
125126
return this.clientRSocketRequesters.get(key);
126127
}
127128

@@ -146,6 +147,7 @@ private void handleConnectionSetup(Message<DataBuffer> connectMessage) {
146147
RSocketRequester rsocketRequester =
147148
messageHeaders.get(RSocketRequesterMethodArgumentResolver.RSOCKET_REQUESTER_HEADER,
148149
RSocketRequester.class);
150+
Assert.notNull(rsocketRequester, "'rsocketRequester' can not be null");
149151
this.clientRSocketRequesters.put(rsocketRequesterKey, rsocketRequester);
150152
RSocketConnectedEvent rSocketConnectedEvent =
151153
new RSocketConnectedEvent(this, messageHeaders, dataBuffer, rsocketRequester); // NOSONAR
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides classes for RSocket XML namespace parsing and configuration support.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.rsocket.config;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Provides RSocket 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.rsocket.dsl;

spring-integration-rsocket/src/main/java/org/springframework/integration/rsocket/inbound/RSocketInboundGateway.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Arrays;
2020
import java.util.concurrent.atomic.AtomicReference;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.reactivestreams.Publisher;
2324
import reactor.core.publisher.Flux;
2425
import reactor.core.publisher.Mono;
@@ -37,7 +38,6 @@
3738
import org.springframework.integration.rsocket.IntegrationRSocketEndpoint;
3839
import org.springframework.integration.rsocket.RSocketInteractionModel;
3940
import org.springframework.integration.support.MessageBuilder;
40-
import org.springframework.lang.Nullable;
4141
import org.springframework.messaging.Message;
4242
import org.springframework.messaging.MessageDeliveryException;
4343
import org.springframework.messaging.MessageHeaders;
@@ -78,11 +78,9 @@ public class RSocketInboundGateway extends MessagingGatewaySupport implements In
7878

7979
private RSocketStrategies rsocketStrategies = RSocketStrategies.create();
8080

81-
@Nullable
82-
private AbstractRSocketConnector rsocketConnector;
81+
private @Nullable AbstractRSocketConnector rsocketConnector;
8382

84-
@Nullable
85-
private ResolvableType requestElementType;
83+
private @Nullable ResolvableType requestElementType;
8684

8785
private boolean decodeFluxAsUnit;
8886

@@ -188,8 +186,8 @@ protected void onInit() {
188186
@Override
189187
protected void doStart() {
190188
super.doStart();
191-
if (this.rsocketConnector instanceof ClientRSocketConnector) {
192-
((ClientRSocketConnector) this.rsocketConnector).connect();
189+
if (this.rsocketConnector instanceof ClientRSocketConnector clientRSocketConnector) {
190+
clientRSocketConnector.connect();
193191
}
194192
}
195193

@@ -265,8 +263,8 @@ private Object decodePayload(Message<?> requestMessage) {
265263

266264
// The MessagingRSocket logic ensures that we can have only a single DataBuffer payload or Flux<DataBuffer>.
267265
Decoder<Object> decoder = this.rsocketStrategies.decoder(elementType, mimeType);
268-
if (payload instanceof DataBuffer) {
269-
return decoder.decode((DataBuffer) payload, elementType, mimeType, null);
266+
if (payload instanceof DataBuffer dataBuffer) {
267+
return decoder.decode(dataBuffer, elementType, mimeType, null);
270268
}
271269
else if (this.decodeFluxAsUnit) {
272270
return decoder.decode((Publisher<DataBuffer>) payload, elementType, mimeType, null);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Provides classes representing inbound RSocket components.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.integration.rsocket.inbound;

0 commit comments

Comments
 (0)