Skip to content

Commit

Permalink
Refine null-safety in DestinationPatternsMessageCondition
Browse files Browse the repository at this point in the history
  • Loading branch information
sdeleuze committed Jan 23, 2025
1 parent 35fede1 commit 673e2b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand All @@ -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<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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 673e2b0

Please sign in to comment.