Specify generic type nullness in spring-messaging

See gh-34140
This commit is contained in:
Sébastien Deleuze 2025-01-13 20:53:12 +01:00
parent 8299a617b9
commit 8b64e2735e
3 changed files with 14 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -71,7 +71,7 @@ public class DestinationPatternsMessageCondition
* @param patterns the URL patterns to match to, or if 0 then always match * @param patterns the URL patterns to match to, or if 0 then always match
* @param matcher the {@code PathMatcher} to use * @param matcher the {@code PathMatcher} to use
*/ */
public DestinationPatternsMessageCondition(String[] patterns, @Nullable PathMatcher matcher) { public DestinationPatternsMessageCondition(@Nullable String[] patterns, @Nullable PathMatcher matcher) {
this(patterns, new SimpleRouteMatcher(matcher != null ? matcher : new AntPathMatcher())); this(patterns, new SimpleRouteMatcher(matcher != null ? matcher : new AntPathMatcher()));
} }
@ -81,13 +81,14 @@ public class DestinationPatternsMessageCondition
* @param routeMatcher the {@code RouteMatcher} to use * @param routeMatcher the {@code RouteMatcher} to use
* @since 5.2 * @since 5.2
*/ */
public DestinationPatternsMessageCondition(String[] patterns, RouteMatcher routeMatcher) { public DestinationPatternsMessageCondition(@Nullable String[] patterns, RouteMatcher routeMatcher) {
this(Collections.unmodifiableSet(prependLeadingSlash(patterns, routeMatcher)), routeMatcher); this(Collections.unmodifiableSet(prependLeadingSlash(patterns, routeMatcher)), routeMatcher);
} }
private static Set<String> prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher) { @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1125
private static Set<@Nullable String> prependLeadingSlash(@Nullable String[] patterns, RouteMatcher routeMatcher) {
boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a"); boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a");
Set<String> result = CollectionUtils.newLinkedHashSet(patterns.length); Set<@Nullable String> result = CollectionUtils.newLinkedHashSet(patterns.length);
for (String pattern : patterns) { for (String pattern : patterns) {
if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) { if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
pattern = "/" + pattern; pattern = "/" + pattern;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -215,13 +215,13 @@ final class RSocketServiceMethod {
return this.method; return this.method;
} }
public @Nullable Object invoke(Object[] arguments) { public @Nullable Object invoke(@Nullable Object[] arguments) {
RSocketRequestValues.Builder requestValues = RSocketRequestValues.builder(this.route); RSocketRequestValues.Builder requestValues = RSocketRequestValues.builder(this.route);
applyArguments(requestValues, arguments); applyArguments(requestValues, arguments);
return this.responseFunction.apply(requestValues.build()); return this.responseFunction.apply(requestValues.build());
} }
private void applyArguments(RSocketRequestValues.Builder requestValues, Object[] arguments) { private void applyArguments(RSocketRequestValues.Builder requestValues, @Nullable Object[] arguments) {
Assert.isTrue(arguments.length == this.parameters.length, "Method argument mismatch"); Assert.isTrue(arguments.length == this.parameters.length, "Method argument mismatch");
for (int i = 0; i < arguments.length; i++) { for (int i = 0; i < arguments.length; i++) {
Object value = arguments[i]; Object value = arguments[i];

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -422,13 +422,13 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
} }
private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) { private SimpMessageMappingInfo createMessageMappingCondition(String[] destinations) {
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE, return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE,
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
} }
private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) { private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) {
String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations);
return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE, return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE,
new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher));
} }
@ -438,11 +438,11 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan
* @return a new array with updated destinations * @return a new array with updated destinations
* @since 4.2 * @since 4.2
*/ */
protected String[] resolveEmbeddedValuesInDestinations(String[] destinations) { protected @Nullable String[] resolveEmbeddedValuesInDestinations(String[] destinations) {
if (this.valueResolver == null) { if (this.valueResolver == null) {
return destinations; return destinations;
} }
String[] result = new String[destinations.length]; @Nullable String[] result = new String[destinations.length];
for (int i = 0; i < destinations.length; i++) { for (int i = 0; i < destinations.length; i++) {
result[i] = this.valueResolver.resolveStringValue(destinations[i]); result[i] = this.valueResolver.resolveStringValue(destinations[i]);
} }