Skip to content

Commit 673e2b0

Browse files
committed
Refine null-safety in DestinationPatternsMessageCondition
See gh-28797
1 parent 35fede1 commit 673e2b0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public DestinationPatternsMessageCondition(String... patterns) {
7171
* @param patterns the URL patterns to match to, or if 0 then always match
7272
* @param matcher the {@code PathMatcher} to use
7373
*/
74-
public DestinationPatternsMessageCondition(@Nullable String[] patterns, @Nullable PathMatcher matcher) {
74+
public DestinationPatternsMessageCondition(String[] patterns, @Nullable PathMatcher matcher) {
7575
this(patterns, new SimpleRouteMatcher(matcher != null ? matcher : new AntPathMatcher()));
7676
}
7777

@@ -81,14 +81,13 @@ public DestinationPatternsMessageCondition(@Nullable String[] patterns, @Nullabl
8181
* @param routeMatcher the {@code RouteMatcher} to use
8282
* @since 5.2
8383
*/
84-
public DestinationPatternsMessageCondition(@Nullable String[] patterns, RouteMatcher routeMatcher) {
84+
public DestinationPatternsMessageCondition(String[] patterns, RouteMatcher routeMatcher) {
8585
this(Collections.unmodifiableSet(prependLeadingSlash(patterns, routeMatcher)), routeMatcher);
8686
}
8787

88-
@SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1125
89-
private static Set<@Nullable String> prependLeadingSlash(@Nullable String[] patterns, RouteMatcher routeMatcher) {
88+
private static Set<String> prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher) {
9089
boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a");
91-
Set<@Nullable String> result = CollectionUtils.newLinkedHashSet(patterns.length);
90+
Set<String> result = CollectionUtils.newLinkedHashSet(patterns.length);
9291
for (String pattern : patterns) {
9392
if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
9493
pattern = "/" + pattern;

spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.LinkedHashSet;
2424
import java.util.List;
2525
import java.util.Map;
26+
import java.util.Objects;
2627
import java.util.Set;
2728

2829
import org.apache.commons.logging.Log;
@@ -422,13 +423,13 @@ protected boolean isHandler(Class<?> beanType) {
422423
}
423424

424425
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
425-
@Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
426+
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
426427
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
427428
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
428429
}
429430

430431
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
431-
@Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
432+
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
432433
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
433434
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
434435
}
@@ -438,13 +439,13 @@ private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinat
438439
* @return a new array with updated destinations
439440
* @since 4.2
440441
*/
441-
protected @Nullable String[] resolveEmbeddedValuesInDestinations(String[] destinations) {
442+
protected String[] resolveEmbeddedValuesInDestinations(String[] destinations) {
442443
if (this.valueResolver == null) {
443444
return destinations;
444445
}
445-
@Nullable String[] result = new String[destinations.length];
446+
String[] result = new String[destinations.length];
446447
for (int i = 0; i < destinations.length; i++) {
447-
result[i] = this.valueResolver.resolveStringValue(destinations[i]);
448+
result[i] = Objects.requireNonNull(this.valueResolver.resolveStringValue(destinations[i]));
448449
}
449450
return result;
450451
}

0 commit comments

Comments
 (0)