Skip to content

Commit abccba2

Browse files
committed
Refine null-safety in the spring-messaging module
Closes gh-34158
1 parent 4fa33df commit abccba2

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractMethodMessageHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -514,12 +514,13 @@ protected void handleMessageInternal(Message<?> message, String lookupDestinatio
514514
handleMatch(bestMatch.mapping, bestMatch.handlerMethod, lookupDestination, message);
515515
}
516516

517-
@SuppressWarnings("NullAway")
518517
private void addMatchesToCollection(Collection<T> mappingsToCheck, Message<?> message, List<Match> matches) {
519518
for (T mapping : mappingsToCheck) {
520519
T match = getMatchingMapping(mapping, message);
521520
if (match != null) {
522-
matches.add(new Match(match, this.handlerMethods.get(mapping)));
521+
HandlerMethod handlerMethod = this.handlerMethods.get(mapping);
522+
Assert.state(handlerMethod != null, "HandlerMethod must not be null");
523+
matches.add(new Match(match, handlerMethod));
523524
}
524525
}
525526
}

spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,15 @@ protected Mono<Void> handleMatch(T mapping, HandlerMethod handlerMethod, Message
496496
*/
497497
protected abstract RouteMatcher.@Nullable Route getDestination(Message<?> message);
498498

499-
@SuppressWarnings("NullAway")
500499
private void addMatchesToCollection(
501500
Collection<T> mappingsToCheck, Message<?> message, List<Match<T>> matches) {
502501

503502
for (T mapping : mappingsToCheck) {
504503
T match = getMatchingMapping(mapping, message);
505504
if (match != null) {
506-
matches.add(new Match<>(match, this.handlerMethods.get(mapping)));
505+
HandlerMethod handlerMethod = this.handlerMethods.get(mapping);
506+
Assert.state(handlerMethod != null, "HandlerMethod must not be null");
507+
matches.add(new Match<>(match, handlerMethod));
507508
}
508509
}
509510
}

spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static MethodParameter[] initMethodParameters(Method method) {
9090
return parameters;
9191
}
9292

93-
@SuppressWarnings("NullAway")
93+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
9494
private static @Nullable String initRoute(
9595
Method method, Class<?> containingClass, RSocketStrategies strategies,
9696
@Nullable StringValueResolver embeddedValueResolver) {

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompDecoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public List<Message<byte[]>> decode(ByteBuffer byteBuffer,
127127
/**
128128
* Decode a single STOMP frame from the given {@code byteBuffer} into a {@link Message}.
129129
*/
130-
@SuppressWarnings("NullAway")
130+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
131131
private @Nullable Message<byte[]> decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap<String, String> headers) {
132132
Message<byte[]> decodedMessage = null;
133133
skipEol(byteBuffer);

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaderAccessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public boolean isHeartbeat() {
236236
return (SimpMessageType.HEARTBEAT == getMessageType());
237237
}
238238

239-
@SuppressWarnings("NullAway")
239+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
240240
public long[] getHeartbeat() {
241241
String rawValue = getFirstNativeHeader(STOMP_HEARTBEAT_HEADER);
242242
int pos = (rawValue != null ? rawValue.indexOf(',') : -1);

spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public void setHeartbeat(long @Nullable [] heartbeat) {
272272
/**
273273
* Get the heartbeat header.
274274
*/
275-
@SuppressWarnings("NullAway")
275+
@SuppressWarnings("NullAway") // Dataflow analysis limitation
276276
public long @Nullable [] getHeartbeat() {
277277
String rawValue = getFirst(HEARTBEAT);
278278
int pos = (rawValue != null ? rawValue.indexOf(',') : -1);

spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/MethodMessageHandlerTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.Map;
2626
import java.util.Set;
2727

28+
import org.jspecify.annotations.Nullable;
2829
import org.junit.jupiter.api.BeforeEach;
2930
import org.junit.jupiter.api.Test;
3031

@@ -236,7 +237,7 @@ protected String getDestination(Message<?> message) {
236237
}
237238

238239
@Override
239-
protected String getMatchingMapping(String mapping, Message<?> message) {
240+
protected @Nullable String getMatchingMapping(String mapping, Message<?> message) {
240241
String destination = getLookupDestination(getDestination(message));
241242
Assert.notNull(destination, "No destination");
242243
return mapping.equals(destination) || this.pathMatcher.match(mapping, destination) ? mapping : null;

0 commit comments

Comments
 (0)