From 8b64e2735e398820f0cd409e07cf8e08a2467a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 13 Jan 2025 20:53:12 +0100 Subject: [PATCH] Specify generic type nullness in spring-messaging See gh-34140 --- .../handler/DestinationPatternsMessageCondition.java | 11 ++++++----- .../rsocket/service/RSocketServiceMethod.java | 6 +++--- .../support/SimpAnnotationMethodMessageHandler.java | 10 +++++----- 3 files changed, 14 insertions(+), 13 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 4035666940b..e801185a7a1 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 @@ -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"); * 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 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())); } @@ -81,13 +81,14 @@ public class DestinationPatternsMessageCondition * @param routeMatcher the {@code RouteMatcher} to use * @since 5.2 */ - public DestinationPatternsMessageCondition(String[] patterns, RouteMatcher routeMatcher) { + public DestinationPatternsMessageCondition(@Nullable String[] patterns, RouteMatcher routeMatcher) { this(Collections.unmodifiableSet(prependLeadingSlash(patterns, routeMatcher)), routeMatcher); } - private static Set 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"); - Set result = CollectionUtils.newLinkedHashSet(patterns.length); + Set<@Nullable String> 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/rsocket/service/RSocketServiceMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java index 8c16336e495..36c59cce417 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java @@ -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"); * you may not use this file except in compliance with the License. @@ -215,13 +215,13 @@ final class RSocketServiceMethod { return this.method; } - public @Nullable Object invoke(Object[] arguments) { + public @Nullable Object invoke(@Nullable Object[] arguments) { RSocketRequestValues.Builder requestValues = RSocketRequestValues.builder(this.route); applyArguments(requestValues, arguments); 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"); for (int i = 0; i < arguments.length; i++) { Object value = arguments[i]; 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 fd974e59940..e0d23b6be4d 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 @@ -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"); * 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) { - String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); + @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.MESSAGE, new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); } private SimpMessageMappingInfo createSubscribeMappingCondition(String[] destinations) { - String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); + @Nullable String[] resolvedDestinations = resolveEmbeddedValuesInDestinations(destinations); return new SimpMessageMappingInfo(SimpMessageTypeMessageCondition.SUBSCRIBE, new DestinationPatternsMessageCondition(resolvedDestinations, this.pathMatcher)); } @@ -438,11 +438,11 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan * @return a new array with updated destinations * @since 4.2 */ - protected String[] resolveEmbeddedValuesInDestinations(String[] destinations) { + protected @Nullable String[] resolveEmbeddedValuesInDestinations(String[] destinations) { if (this.valueResolver == null) { return destinations; } - String[] result = new String[destinations.length]; + @Nullable String[] result = new String[destinations.length]; for (int i = 0; i < destinations.length; i++) { result[i] = this.valueResolver.resolveStringValue(destinations[i]); }