From 673e2b0dd201eb66a92d8e1d4724f3497922b23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= <141109+sdeleuze@users.noreply.github.com> Date: Thu, 23 Jan 2025 14:16:36 +0100 Subject: [PATCH] Refine null-safety in DestinationPatternsMessageCondition See gh-28797 --- .../handler/DestinationPatternsMessageCondition.java | 9 ++++----- .../support/SimpAnnotationMethodMessageHandler.java | 11 ++++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java index e801185a7a12..c42593d2d623 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java @@ -71,7 +71,7 @@ public DestinationPatternsMessageCondition(String... patterns) { * @param patterns the URL patterns to match to, or if 0 then always match * @param matcher the {@code PathMatcher} to use */ - public DestinationPatternsMessageCondition(@Nullable String[] patterns, @Nullable PathMatcher matcher) { + public DestinationPatternsMessageCondition(String[] patterns, @Nullable PathMatcher matcher) { this(patterns, new SimpleRouteMatcher(matcher != null ? matcher : new AntPathMatcher())); } @@ -81,14 +81,13 @@ public DestinationPatternsMessageCondition(@Nullable String[] patterns, @Nullabl * @param routeMatcher the {@code RouteMatcher} to use * @since 5.2 */ - public DestinationPatternsMessageCondition(@Nullable String[] patterns, RouteMatcher routeMatcher) { + public DestinationPatternsMessageCondition(String[] patterns, RouteMatcher routeMatcher) { this(Collections.unmodifiableSet(prependLeadingSlash(patterns, routeMatcher)), routeMatcher); } - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1125 - private static Set<@Nullable String> prependLeadingSlash(@Nullable String[] patterns, RouteMatcher routeMatcher) { + private static Set prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher) { boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a"); - Set<@Nullable String> result = CollectionUtils.newLinkedHashSet(patterns.length); + Set result = CollectionUtils.newLinkedHashSet(patterns.length); for (String pattern : patterns) { if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) { pattern = "/" + pattern; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index e0d23b6be4db..ce19fca640b3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.apache.commons.logging.Log; @@ -422,13 +423,13 @@ protected boolean isHandler(Class beanType) { } private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) { - @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); + String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE, new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); } private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) { - @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); + String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE, new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); } @@ -438,13 +439,13 @@ private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinat * @return a new array with updated destinations * @since 4.2 */ - protected @Nullable String[] resolveEmbeddedValuesInDestinations(String[] destinations) { + protected String[] resolveEmbeddedValuesInDestinations(String[] destinations) { if (this.valueResolver == null) { return destinations; } - @Nullable String[] result = new String[destinations.length]; + String[] result = new String[destinations.length]; for (int i = 0; i < destinations.length; i++) { - result[i] = this.valueResolver.resolveStringValue(destinations[i]); + result[i] = Objects.requireNonNull(this.valueResolver.resolveStringValue(destinations[i])); } return result; }