Skip to content

Commit 8fdee30

Browse files
authored
GH-10083: Apply Nullability to STMOP module
Related to: #10083 Signed-off-by: Jooyoung Pyoung <[email protected]>
1 parent faa3eb4 commit 8fdee30

14 files changed

+68
-33
lines changed

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/AbstractStompSessionManager.java

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.apache.commons.logging.Log;
3333
import org.apache.commons.logging.LogFactory;
34+
import org.jspecify.annotations.Nullable;
3435

3536
import org.springframework.beans.factory.BeanNameAware;
3637
import org.springframework.beans.factory.DisposableBean;
@@ -39,7 +40,6 @@
3940
import org.springframework.context.SmartLifecycle;
4041
import org.springframework.integration.stomp.event.StompConnectionFailedEvent;
4142
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
42-
import org.springframework.lang.Nullable;
4343
import org.springframework.messaging.simp.stomp.StompClientSupport;
4444
import org.springframework.messaging.simp.stomp.StompCommand;
4545
import org.springframework.messaging.simp.stomp.StompHeaders;
@@ -94,23 +94,24 @@ public abstract class AbstractStompSessionManager implements StompSessionManager
9494

9595
private int phase = Integer.MAX_VALUE / 2;
9696

97+
@SuppressWarnings("NullAway.Init")
9798
private ApplicationEventPublisher applicationEventPublisher;
9899

99-
private StompHeaders connectHeaders;
100+
private @Nullable StompHeaders connectHeaders;
100101

101102
private boolean autoReceipt;
102103

103104
private long recoveryInterval = DEFAULT_RECOVERY_INTERVAL;
104105

105-
private String name;
106+
private @Nullable String name;
106107

107108
private volatile boolean connecting;
108109

109110
private volatile boolean connected;
110111

111-
private volatile CompletableFuture<StompSession> stompSessionFuture;
112+
private volatile @Nullable CompletableFuture<StompSession> stompSessionFuture;
112113

113-
private volatile ScheduledFuture<?> reconnectFuture;
114+
private volatile @Nullable ScheduledFuture<?> reconnectFuture;
114115

115116
public AbstractStompSessionManager(StompClientSupport stompClient) {
116117
Assert.notNull(stompClient, "'stompClient' is required.");
@@ -226,6 +227,8 @@ private void connect() {
226227
}
227228

228229
private CountDownLatch addStompSessionCallback(int currentEpoch) {
230+
Assert.notNull(this.stompSessionFuture, "'stompSessionFuture' is required.");
231+
229232
CountDownLatch connectLatch = new CountDownLatch(1);
230233
this.stompSessionFuture.whenComplete((stompSession, throwable) -> {
231234
if (throwable == null) {
@@ -254,7 +257,7 @@ private CountDownLatch addStompSessionCallback(int currentEpoch) {
254257
return connectLatch;
255258
}
256259

257-
private void scheduleReconnect(Throwable e) {
260+
private void scheduleReconnect(@Nullable Throwable e) {
258261
this.epoch.incrementAndGet();
259262
this.connecting = false;
260263
this.connected = false;
@@ -353,7 +356,7 @@ public void disconnect(StompSessionHandler handler) {
353356
this.compositeStompSessionHandler.removeHandler(handler);
354357
}
355358

356-
protected StompHeaders getConnectHeaders() {
359+
protected @Nullable StompHeaders getConnectHeaders() {
357360
return this.connectHeaders;
358361
}
359362

@@ -374,7 +377,7 @@ private class CompositeStompSessionHandler extends StompSessionHandlerAdapter {
374377

375378
private final Lock delegatesMonitor = new ReentrantLock();
376379

377-
private volatile StompSession session;
380+
private volatile @Nullable StompSession session;
378381

379382
CompositeStompSessionHandler() {
380383
}
@@ -383,7 +386,11 @@ void addHandler(StompSessionHandler delegate) {
383386
this.delegatesMonitor.lock();
384387
try {
385388
if (this.session != null) {
386-
delegate.afterConnected(this.session, getConnectHeaders());
389+
StompHeaders headers = getConnectHeaders();
390+
if (headers == null) {
391+
headers = new StompHeaders();
392+
}
393+
delegate.afterConnected(this.session, headers);
387394
}
388395
this.delegates.add(delegate);
389396
}
@@ -443,7 +450,7 @@ public void handleTransportError(StompSession session, Throwable exception) {
443450
}
444451

445452
@Override
446-
public void handleFrame(StompHeaders headers, Object payload) {
453+
public void handleFrame(StompHeaders headers, @Nullable Object payload) {
447454
this.delegatesMonitor.lock();
448455
try {
449456
for (StompSessionHandler delegate : this.delegates) {

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/WebSocketStompSessionManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import java.util.Arrays;
2020
import java.util.concurrent.CompletableFuture;
2121

22+
import org.jspecify.annotations.Nullable;
23+
2224
import org.springframework.messaging.simp.stomp.StompSession;
2325
import org.springframework.messaging.simp.stomp.StompSessionHandler;
2426
import org.springframework.util.Assert;
@@ -41,13 +43,14 @@ public class WebSocketStompSessionManager extends AbstractStompSessionManager {
4143

4244
private final Object[] uriVariables;
4345

44-
private volatile WebSocketHttpHeaders handshakeHeaders;
46+
private volatile @Nullable WebSocketHttpHeaders handshakeHeaders;
4547

4648
public WebSocketStompSessionManager(WebSocketStompClient webSocketStompClient, String url, Object... uriVariables) {
4749
super(webSocketStompClient);
4850
Assert.hasText(url, "'url' must not be empty.");
4951
this.url = url;
50-
this.uriVariables = uriVariables != null ? Arrays.copyOf(uriVariables, uriVariables.length) : null;
52+
this.uriVariables = uriVariables != null ?
53+
Arrays.copyOf(uriVariables, uriVariables.length) : new Object[0];
5154
}
5255

5356
public void setHandshakeHeaders(WebSocketHttpHeaders handshakeHeaders) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Contains parser classes for the STOMP namespace support.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.stomp.config;

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/event/StompConnectionFailedEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.stomp.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* The {@link StompIntegrationEvent} implementation for the failed connection exceptions.
2123
*
@@ -25,7 +27,7 @@
2527
@SuppressWarnings("serial")
2628
public class StompConnectionFailedEvent extends StompIntegrationEvent {
2729

28-
public StompConnectionFailedEvent(Object source, Throwable cause) {
30+
public StompConnectionFailedEvent(Object source, @Nullable Throwable cause) {
2931
super(source, cause);
3032
}
3133

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/event/StompExceptionEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.stomp.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
/**
2022
* The {@link StompIntegrationEvent} implementation for the exception from STOMP Adapters.
2123
*
@@ -25,7 +27,7 @@
2527
@SuppressWarnings("serial")
2628
public class StompExceptionEvent extends StompIntegrationEvent {
2729

28-
public StompExceptionEvent(Object source, Throwable cause) {
30+
public StompExceptionEvent(Object source, @Nullable Throwable cause) {
2931
super(source, cause);
3032
}
3133

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/event/StompIntegrationEvent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.stomp.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.integration.events.IntegrationEvent;
2022

2123
/**
@@ -33,7 +35,7 @@ public StompIntegrationEvent(Object source) {
3335
super(source);
3436
}
3537

36-
public StompIntegrationEvent(Object source, Throwable cause) {
38+
public StompIntegrationEvent(Object source, @Nullable Throwable cause) {
3739
super(source, cause);
3840
}
3941

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/event/StompReceiptEvent.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.integration.stomp.event;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.messaging.Message;
2022
import org.springframework.messaging.simp.stomp.StompCommand;
2123

@@ -31,30 +33,31 @@
3133
@SuppressWarnings("serial")
3234
public class StompReceiptEvent extends StompIntegrationEvent {
3335

34-
private final String destination;
36+
private final @Nullable String destination;
3537

36-
private final String receiptId;
38+
private final @Nullable String receiptId;
3739

3840
private final StompCommand stompCommand;
3941

4042
private final boolean lost;
4143

42-
private Message<?> message;
44+
private @Nullable Message<?> message;
45+
46+
public StompReceiptEvent(Object source, @Nullable String destination, @Nullable String receiptId,
47+
StompCommand stompCommand, boolean lost) {
4348

44-
public StompReceiptEvent(Object source, String destination, String receiptId, StompCommand stompCommand,
45-
boolean lost) {
4649
super(source);
4750
this.destination = destination;
4851
this.receiptId = receiptId;
4952
this.stompCommand = stompCommand;
5053
this.lost = lost;
5154
}
5255

53-
public String getDestination() {
56+
public @Nullable String getDestination() {
5457
return this.destination;
5558
}
5659

57-
public String getReceiptId() {
60+
public @Nullable String getReceiptId() {
5861
return this.receiptId;
5962
}
6063

@@ -66,7 +69,7 @@ public boolean isLost() {
6669
return this.lost;
6770
}
6871

69-
public Message<?> getMessage() {
72+
public @Nullable Message<?> getMessage() {
7073
return this.message;
7174
}
7275

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* Provides classes which represent STOMP events.
3+
*/
4+
@org.jspecify.annotations.NullMarked
5+
package org.springframework.integration.stomp.event;

spring-integration-stomp/src/main/java/org/springframework/integration/stomp/inbound/StompInboundChannelAdapter.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.util.concurrent.locks.Lock;
2626
import java.util.concurrent.locks.ReentrantLock;
2727

28+
import org.jspecify.annotations.Nullable;
29+
2830
import org.springframework.context.ApplicationEventPublisher;
2931
import org.springframework.context.ApplicationEventPublisherAware;
3032
import org.springframework.context.Lifecycle;
@@ -39,7 +41,6 @@
3941
import org.springframework.jmx.export.annotation.ManagedAttribute;
4042
import org.springframework.jmx.export.annotation.ManagedOperation;
4143
import org.springframework.jmx.export.annotation.ManagedResource;
42-
import org.springframework.lang.Nullable;
4344
import org.springframework.messaging.Message;
4445
import org.springframework.messaging.MessageChannel;
4546
import org.springframework.messaging.simp.stomp.StompCommand;
@@ -82,13 +83,14 @@ public class StompInboundChannelAdapter extends MessageProducerSupport implement
8283

8384
private final Lock destinationLock = new ReentrantLock();
8485

86+
@SuppressWarnings("NullAway.Init")
8587
private ApplicationEventPublisher applicationEventPublisher;
8688

8789
private Class<?> payloadType = String.class;
8890

8991
private HeaderMapper<StompHeaders> headerMapper = new StompHeaderMapper();
9092

91-
private volatile StompSession stompSession;
93+
private volatile @Nullable StompSession stompSession;
9294

9395
public StompInboundChannelAdapter(StompSessionManager stompSessionManager, String... destinations) {
9496
Assert.notNull(stompSessionManager, "'stompSessionManager' is required.");
@@ -248,14 +250,14 @@ public void afterConnected(StompSession session, StompHeaders connectedHeaders)
248250
}
249251

250252
@Override
251-
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload,
253+
public void handleException(StompSession session, @Nullable StompCommand command, StompHeaders headers, byte[] payload,
252254
Throwable exception) {
253255

254256
String exceptionMessage = "STOMP Frame handling error in the [" + StompInboundChannelAdapter.this + ']';
255257

256258
MessageChannel errorChannel = getErrorChannel();
257259

258-
if (errorChannel != null) {
260+
if (command != null && errorChannel != null) {
259261
StompHeaderAccessor headerAccessor = StompHeaderAccessor.create(command);
260262
headerAccessor.copyHeaders(StompInboundChannelAdapter.this.headerMapper.toHeaders(headers));
261263
Message<byte[]> failedMessage =
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/**
22
* Provides classes which represent inbound STOMP components.
33
*/
4+
@org.jspecify.annotations.NullMarked
45
package org.springframework.integration.stomp.inbound;

0 commit comments

Comments
 (0)