Refine null-safety in DestinationPatternsMessageCondition
See gh-28797
This commit is contained in:
@@ -71,7 +71,7 @@ public class DestinationPatternsMessageCondition
|
||||
* @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 class DestinationPatternsMessageCondition
|
||||
* @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<String> prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher) {
|
||||
boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a");
|
||||
Set<@Nullable String> result = CollectionUtils.newLinkedHashSet(patterns.length);
|
||||
Set<String> result = CollectionUtils.newLinkedHashSet(patterns.length);
|
||||
for (String pattern : patterns) {
|
||||
if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
|
||||
pattern = "/" + pattern;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Comparator;
|
||||
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 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
}
|
||||
|
||||
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 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
|
||||
* @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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user