From ec48c478862ec988ecd63d811cee76b639974514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Fri, 10 Jan 2025 11:39:21 +0100 Subject: [PATCH] Make URI template variables nullable Closes gh-34221 --- .../reactive/MockServerHttpRequest.java | 22 ++++---- .../springframework/test/web/UriAssert.java | 4 +- .../client/match/MockRestRequestMatchers.java | 5 +- .../reactive/server/DefaultWebTestClient.java | 6 +-- .../web/reactive/server/WebTestClient.java | 4 +- ...AbstractMockHttpServletRequestBuilder.java | 6 +-- .../MockHttpServletRequestBuilder.java | 4 +- .../request/MockMvcRequestBuilders.java | 23 ++++---- .../servlet/result/MockMvcResultMatchers.java | 6 +-- .../springframework/http/RequestEntity.java | 26 ++++----- .../web/client/DefaultRestClient.java | 2 +- .../web/client/RestClient.java | 4 +- .../web/client/RestOperations.java | 54 +++++++++---------- .../web/client/RestTemplate.java | 52 +++++++++--------- .../web/util/DefaultUriBuilderFactory.java | 12 ++--- .../springframework/web/util/UriBuilder.java | 4 +- .../web/util/UriComponents.java | 10 ++-- .../web/util/UriComponentsBuilder.java | 6 +-- .../web/util/UriTemplateHandler.java | 6 ++- .../springframework/web/util/UriUtils.java | 4 +- .../web/client/RestOperationsExtensions.kt | 12 ++--- .../reactive/MockServerHttpRequest.java | 22 ++++---- .../function/client/DefaultWebClient.java | 4 +- .../reactive/function/client/WebClient.java | 3 +- .../client/AbstractWebSocketClient.java | 4 +- .../client/ConnectionManagerSupport.java | 5 +- .../web/socket/client/WebSocketClient.java | 2 +- .../client/WebSocketConnectionManager.java | 2 +- .../AnnotatedEndpointConnectionManager.java | 6 +-- .../standard/EndpointConnectionManager.java | 6 +-- .../messaging/WebSocketStompClient.java | 6 +-- .../socket/sockjs/client/SockJsClient.java | 2 +- .../WebSocketConnectionManagerTests.java | 3 +- 33 files changed, 172 insertions(+), 165 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java index f3e10eca5247..26c808d5252f 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -119,7 +119,7 @@ public T getNativeRequest() { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder get(String urlTemplate, Object... uriVars) { + public static BaseBuilder get(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.GET, urlTemplate, uriVars); } @@ -129,7 +129,7 @@ public static BaseBuilder get(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder head(String urlTemplate, Object... uriVars) { + public static BaseBuilder head(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.HEAD, urlTemplate, uriVars); } @@ -139,7 +139,7 @@ public static BaseBuilder head(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder post(String urlTemplate, Object... uriVars) { + public static BodyBuilder post(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.POST, urlTemplate, uriVars); } @@ -150,7 +150,7 @@ public static BodyBuilder post(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder put(String urlTemplate, Object... uriVars) { + public static BodyBuilder put(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.PUT, urlTemplate, uriVars); } @@ -160,7 +160,7 @@ public static BodyBuilder put(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder patch(String urlTemplate, Object... uriVars) { + public static BodyBuilder patch(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.PATCH, urlTemplate, uriVars); } @@ -170,7 +170,7 @@ public static BodyBuilder patch(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder delete(String urlTemplate, Object... uriVars) { + public static BaseBuilder delete(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.DELETE, urlTemplate, uriVars); } @@ -180,7 +180,7 @@ public static BaseBuilder delete(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder options(String urlTemplate, Object... uriVars) { + public static BaseBuilder options(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.OPTIONS, urlTemplate, uriVars); } @@ -205,7 +205,7 @@ public static BodyBuilder method(HttpMethod method, URI url) { * @param vars variables to expand into the template * @return the created builder */ - public static BodyBuilder method(HttpMethod method, String uri, Object... vars) { + public static BodyBuilder method(HttpMethod method, String uri, @Nullable Object... vars) { return method(method, toUri(uri, vars)); } @@ -220,12 +220,12 @@ public static BodyBuilder method(HttpMethod method, String uri, Object... vars) * @deprecated as of Spring Framework 6.0 in favor of {@link #method(HttpMethod, String, Object...)} */ @Deprecated(since = "6.0") - public static BodyBuilder method(String httpMethod, String uri, Object... vars) { + public static BodyBuilder method(String httpMethod, String uri, @Nullable Object... vars) { Assert.hasText(httpMethod, "HTTP method is required."); return new DefaultBodyBuilder(HttpMethod.valueOf(httpMethod), toUri(uri, vars)); } - private static URI toUri(String uri, Object[] vars) { + private static URI toUri(String uri, @Nullable Object[] vars) { return UriComponentsBuilder.fromUriString(uri).buildAndExpand(vars).encode().toUri(); } diff --git a/spring-test/src/main/java/org/springframework/test/web/UriAssert.java b/spring-test/src/main/java/org/springframework/test/web/UriAssert.java index 1373fc3c9b95..f532481f162b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/UriAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/UriAssert.java @@ -56,7 +56,7 @@ public UriAssert(@Nullable String actual, String displayName) { * @param uriVars the values to replace the URI template variables * @see UriComponentsBuilder#buildAndExpand(Object...) */ - public UriAssert isEqualToTemplate(String uriTemplate, Object... uriVars) { + public UriAssert isEqualToTemplate(String uriTemplate, @Nullable Object... uriVars) { String uri = buildUri(uriTemplate, uriVars); return isEqualTo(uri); } @@ -81,7 +81,7 @@ public UriAssert matchesAntPattern(String uriPattern) { } - private String buildUri(String uriTemplate, Object... uriVars) { + private String buildUri(String uriTemplate, @Nullable Object... uriVars) { try { return UriComponentsBuilder.fromUriString(uriTemplate) .buildAndExpand(uriVars).encode().toUriString(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java b/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java index a7397f039aa3..8a72d2b99dbb 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/MockRestRequestMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -23,6 +23,7 @@ import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -98,7 +99,7 @@ public static RequestMatcher requestTo(String expectedUri) { * @param uriVars zero or more URI variables to populate the expected URI * @return the request matcher */ - public static RequestMatcher requestToUriTemplate(String expectedUri, Object... uriVars) { + public static RequestMatcher requestToUriTemplate(String expectedUri, @Nullable Object... uriVars) { Assert.notNull(expectedUri, "'uri' must not be null"); URI uri = UriComponentsBuilder.fromUriString(expectedUri).buildAndExpand(uriVars).encode().toUri(); return requestTo(uri); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 7636b9b36b6e..5c004fb39caa 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.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. @@ -202,13 +202,13 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { } @Override - public RequestBodySpec uri(String uriTemplate, Object... uriVariables) { + public RequestBodySpec uri(String uriTemplate, @Nullable Object... uriVariables) { this.uriTemplate = uriTemplate; return uri(DefaultWebTestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables)); } @Override - public RequestBodySpec uri(String uriTemplate, Map uriVariables) { + public RequestBodySpec uri(String uriTemplate, Map uriVariables) { this.uriTemplate = uriTemplate; return uri(DefaultWebTestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables)); } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 22aedbfde0fb..21852defea4f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -557,7 +557,7 @@ interface UriSpec> { * with a base URI) it will be used to expand the URI template. * @return spec to add headers or perform the exchange */ - S uri(String uri, Object... uriVariables); + S uri(String uri, @Nullable Object... uriVariables); /** * Specify the URI for the request using a URI template and URI variables. @@ -565,7 +565,7 @@ interface UriSpec> { * with a base URI) it will be used to expand the URI template. * @return spec to add headers or perform the exchange */ - S uri(String uri, Map uriVariables); + S uri(String uri, Map uriVariables); /** * Build the URI for the request with a {@link UriBuilder} obtained diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java index 44e45bdfbe84..94c17cdd5e11 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.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. @@ -151,7 +151,7 @@ public B uri(URI uri) { /** * Specify the URI for the request using a URI template and URI variables. */ - public B uri(String uriTemplate, Object... uriVariables) { + public B uri(String uriTemplate, @Nullable Object... uriVariables) { return updateUri(initUri(uriTemplate, uriVariables), uriTemplate); } @@ -161,7 +161,7 @@ private B updateUri(URI uri, @Nullable String uriTemplate) { return self(); } - private static URI initUri(String uri, Object[] vars) { + private static URI initUri(String uri, @Nullable Object[] vars) { Assert.notNull(uri, "'uri' must not be null"); Assert.isTrue(uri.isEmpty() || uri.startsWith("/") || uri.startsWith("http://") || uri.startsWith("https://"), () -> "'uri' should start with a path or be a complete HTTP URI: " + uri); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java index a07eadbee664..b4944fa5c73f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.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. @@ -75,7 +75,7 @@ public MockHttpServletRequestBuilder uri(URI uri) { } @Override - public MockHttpServletRequestBuilder uri(String uriTemplate, Object... uriVariables) { + public MockHttpServletRequestBuilder uri(String uriTemplate, @Nullable Object... uriVariables) { return super.uri(uriTemplate, uriVariables); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java index 00c0c54ceb21..abf479391090 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.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. @@ -19,6 +19,7 @@ import java.net.URI; import jakarta.servlet.DispatcherType; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.mock.web.MockHttpServletRequest; @@ -52,7 +53,7 @@ public abstract class MockMvcRequestBuilders { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder get(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder get(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.GET).uri(uriTemplate, uriVariables); } @@ -70,7 +71,7 @@ public static MockHttpServletRequestBuilder get(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder post(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder post(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.POST).uri(uriTemplate, uriVariables); } @@ -88,7 +89,7 @@ public static MockHttpServletRequestBuilder post(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder put(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder put(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.PUT).uri(uriTemplate, uriVariables); } @@ -106,7 +107,7 @@ public static MockHttpServletRequestBuilder put(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder patch(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder patch(String uriTemplate,@Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.PATCH).uri(uriTemplate, uriVariables); } @@ -124,7 +125,7 @@ public static MockHttpServletRequestBuilder patch(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder delete(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder delete(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.DELETE).uri(uriTemplate, uriVariables); } @@ -142,7 +143,7 @@ public static MockHttpServletRequestBuilder delete(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder options(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder options(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.OPTIONS).uri(uriTemplate, uriVariables); } @@ -161,7 +162,7 @@ public static MockHttpServletRequestBuilder options(URI uri) { * @param uriVariables zero or more URI variables * @since 4.1 */ - public static MockHttpServletRequestBuilder head(String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder head(String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(HttpMethod.HEAD).uri(uriTemplate, uriVariables); } @@ -180,7 +181,7 @@ public static MockHttpServletRequestBuilder head(URI uri) { * @param uriTemplate a URI template; the resulting URI will be encoded * @param uriVariables zero or more URI variables */ - public static MockHttpServletRequestBuilder request(HttpMethod method, String uriTemplate, Object... uriVariables) { + public static MockHttpServletRequestBuilder request(HttpMethod method, String uriTemplate, @Nullable Object... uriVariables) { return new MockHttpServletRequestBuilder(method).uri(uriTemplate, uriVariables); } @@ -213,7 +214,7 @@ public static MockHttpServletRequestBuilder request(String httpMethod, URI uri) * @param uriVariables zero or more URI variables * @since 5.0 */ - public static MockMultipartHttpServletRequestBuilder multipart(String uriTemplate, Object... uriVariables) { + public static MockMultipartHttpServletRequestBuilder multipart(String uriTemplate, @Nullable Object... uriVariables) { MockMultipartHttpServletRequestBuilder builder = new MockMultipartHttpServletRequestBuilder(); builder.uri(uriTemplate, uriVariables); return builder; @@ -227,7 +228,7 @@ public static MockMultipartHttpServletRequestBuilder multipart(String uriTemplat * @param uriVariables zero or more URI variables * @since 5.3.22 */ - public static MockMultipartHttpServletRequestBuilder multipart(HttpMethod httpMethod, String uriTemplate, Object... uriVariables) { + public static MockMultipartHttpServletRequestBuilder multipart(HttpMethod httpMethod, String uriTemplate, @Nullable Object... uriVariables) { MockMultipartHttpServletRequestBuilder builder = new MockMultipartHttpServletRequestBuilder(httpMethod); builder.uri(uriTemplate, uriVariables); return builder; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java index a5cc5e036a2a..7c800058e2e3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 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. @@ -98,7 +98,7 @@ public static ResultMatcher forwardedUrl(@Nullable String expectedUrl) { * @param uriVars zero or more URI variables to populate the template * @see UriComponentsBuilder#fromUriString(String) */ - public static ResultMatcher forwardedUrlTemplate(String urlTemplate, Object... uriVars) { + public static ResultMatcher forwardedUrlTemplate(String urlTemplate, @Nullable Object... uriVars) { String uri = UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); return forwardedUrl(uri); } @@ -137,7 +137,7 @@ public static ResultMatcher redirectedUrl(String expectedUrl) { * @param uriVars zero or more URI variables to populate the template * @see UriComponentsBuilder#fromUriString(String) */ - public static ResultMatcher redirectedUrlTemplate(String urlTemplate, Object... uriVars) { + public static ResultMatcher redirectedUrlTemplate(String urlTemplate, @Nullable Object... uriVars) { String uri = UriComponentsBuilder.fromUriString(urlTemplate).buildAndExpand(uriVars).encode().toUriString(); return redirectedUrl(uri); } diff --git a/spring-web/src/main/java/org/springframework/http/RequestEntity.java b/spring-web/src/main/java/org/springframework/http/RequestEntity.java index 2f15ff57c7c4..bcbac6914ad4 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -304,7 +304,7 @@ public static BodyBuilder method(HttpMethod method, URI url) { * @return the created builder * @since 5.3 */ - public static BodyBuilder method(HttpMethod method, String uriTemplate, Object... uriVariables) { + public static BodyBuilder method(HttpMethod method, String uriTemplate, @Nullable Object... uriVariables) { return new DefaultBodyBuilder(method, uriTemplate, uriVariables); } @@ -336,7 +336,7 @@ public static HeadersBuilder get(URI url) { * @return the created builder * @since 5.3 */ - public static HeadersBuilder get(String uriTemplate, Object... uriVariables) { + public static HeadersBuilder get(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.GET, uriTemplate, uriVariables); } @@ -356,7 +356,7 @@ public static HeadersBuilder head(URI url) { * @return the created builder * @since 5.3 */ - public static HeadersBuilder head(String uriTemplate, Object... uriVariables) { + public static HeadersBuilder head(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.HEAD, uriTemplate, uriVariables); } @@ -376,7 +376,7 @@ public static BodyBuilder post(URI url) { * @return the created builder * @since 5.3 */ - public static BodyBuilder post(String uriTemplate, Object... uriVariables) { + public static BodyBuilder post(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.POST, uriTemplate, uriVariables); } @@ -396,7 +396,7 @@ public static BodyBuilder put(URI url) { * @return the created builder * @since 5.3 */ - public static BodyBuilder put(String uriTemplate, Object... uriVariables) { + public static BodyBuilder put(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.PUT, uriTemplate, uriVariables); } @@ -416,7 +416,7 @@ public static BodyBuilder patch(URI url) { * @return the created builder * @since 5.3 */ - public static BodyBuilder patch(String uriTemplate, Object... uriVariables) { + public static BodyBuilder patch(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.PATCH, uriTemplate, uriVariables); } @@ -436,7 +436,7 @@ public static HeadersBuilder delete(URI url) { * @return the created builder * @since 5.3 */ - public static HeadersBuilder delete(String uriTemplate, Object... uriVariables) { + public static HeadersBuilder delete(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.DELETE, uriTemplate, uriVariables); } @@ -456,7 +456,7 @@ public static HeadersBuilder options(URI url) { * @return the created builder * @since 5.3 */ - public static HeadersBuilder options(String uriTemplate, Object... uriVariables) { + public static HeadersBuilder options(String uriTemplate, @Nullable Object... uriVariables) { return method(HttpMethod.OPTIONS, uriTemplate, uriVariables); } @@ -601,9 +601,9 @@ private static class DefaultBodyBuilder implements BodyBuilder { private final @Nullable String uriTemplate; - private final Object @Nullable [] uriVarsArray; + private final @Nullable Object @Nullable [] uriVarsArray; - private final @Nullable Map uriVarsMap; + private final @Nullable Map uriVarsMap; DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; @@ -613,7 +613,7 @@ private static class DefaultBodyBuilder implements BodyBuilder { this.uriVarsMap = null; } - DefaultBodyBuilder(HttpMethod method, String uriTemplate, Object... uriVars) { + DefaultBodyBuilder(HttpMethod method, String uriTemplate, @Nullable Object... uriVars) { this.method = method; this.uri = null; this.uriTemplate = uriTemplate; @@ -621,7 +621,7 @@ private static class DefaultBodyBuilder implements BodyBuilder { this.uriVarsMap = null; } - DefaultBodyBuilder(HttpMethod method, String uriTemplate, Map uriVars) { + DefaultBodyBuilder(HttpMethod method, String uriTemplate, Map uriVars) { this.method = method; this.uri = null; this.uriTemplate = uriTemplate; diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index 0c0a70ef7400..c1244a754785 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -305,7 +305,7 @@ public DefaultRequestBodyUriSpec(HttpMethod httpMethod) { } @Override - public RequestBodySpec uri(String uriTemplate, Object... uriVariables) { + public RequestBodySpec uri(String uriTemplate, @Nullable Object... uriVariables) { UriBuilder uriBuilder = uriBuilderFactory.uriString(uriTemplate); attribute(URI_TEMPLATE_ATTRIBUTE, uriBuilder.toUriString()); return uri(DefaultRestClient.this.uriBuilderFactory.expand(uriTemplate, uriVariables)); diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClient.java b/spring-web/src/main/java/org/springframework/web/client/RestClient.java index be5b21fcd4ed..391ab01c1ee1 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClient.java @@ -503,14 +503,14 @@ interface UriSpec> { *

If a {@link UriBuilderFactory} was configured for the client (for example, * with a base URI) it will be used to expand the URI template. */ - S uri(String uri, Object... uriVariables); + S uri(String uri, @Nullable Object... uriVariables); /** * Specify the URI for the request using a URI template and URI variables. *

If a {@link UriBuilderFactory} was configured for the client (for example, * with a base URI) it will be used to expand the URI template. */ - S uri(String uri, Map uriVariables); + S uri(String uri, Map uriVariables); /** * Specify the URI starting with a URI template and finishing off with a diff --git a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java b/spring-web/src/main/java/org/springframework/web/client/RestOperations.java index bcdb4214cec7..4f1132cc0eb5 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestOperations.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestOperations.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. @@ -53,7 +53,7 @@ public interface RestOperations { * @param uriVariables the variables to expand the template * @return the converted object */ - @Nullable T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException; + @Nullable T getForObject(String url, Class responseType, @Nullable Object... uriVariables) throws RestClientException; /** * Retrieve a representation by doing a GET on the URI template. @@ -64,7 +64,7 @@ public interface RestOperations { * @param uriVariables the map containing variables for the URI template * @return the converted object */ - @Nullable T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException; + @Nullable T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException; /** * Retrieve a representation by doing a GET on the URL. @@ -85,7 +85,7 @@ public interface RestOperations { * @return the entity * @since 3.0.2 */ - ResponseEntity getForEntity(String url, Class responseType, Object... uriVariables) + ResponseEntity getForEntity(String url, Class responseType, @Nullable Object... uriVariables) throws RestClientException; /** @@ -98,7 +98,7 @@ ResponseEntity getForEntity(String url, Class responseType, Object... * @return the converted object * @since 3.0.2 */ - ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) + ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) throws RestClientException; /** @@ -121,7 +121,7 @@ ResponseEntity getForEntity(String url, Class responseType, Map ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) throws RestClientException; + HttpHeaders headForHeaders(String url, Map uriVariables) throws RestClientException; /** * Retrieve all headers of the resource specified by the URL. @@ -159,7 +159,7 @@ ResponseEntity getForEntity(String url, Class responseType, Map ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) + @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** @@ -217,7 +217,7 @@ ResponseEntity getForEntity(String url, Class responseType, Map @Nullable T postForObject(String url, @Nullable Object request, Class responseType, - Object... uriVariables) throws RestClientException; + @Nullable Object... uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -238,7 +238,7 @@ ResponseEntity getForEntity(String url, Class responseType, Map @Nullable T postForObject(String url, @Nullable Object request, Class responseType, - Map uriVariables) throws RestClientException; + Map uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URL, @@ -277,7 +277,7 @@ ResponseEntity getForEntity(String url, Class responseType, Map ResponseEntity postForEntity(String url, @Nullable Object request, Class responseType, - Object... uriVariables) throws RestClientException; + @Nullable Object... uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -298,7 +298,7 @@ ResponseEntity postForEntity(String url, @Nullable Object request, Class< * @see HttpEntity */ ResponseEntity postForEntity(String url, @Nullable Object request, Class responseType, - Map uriVariables) throws RestClientException; + Map uriVariables) throws RestClientException; /** * Create a new resource by POSTing the given object to the URL, @@ -332,7 +332,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param uriVariables the variables to expand the template * @see HttpEntity */ - void put(String url, @Nullable Object request, Object... uriVariables) throws RestClientException; + void put(String url, @Nullable Object request, @Nullable Object... uriVariables) throws RestClientException; /** * Creates a new resource by PUTting the given object to URI template. @@ -344,7 +344,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param uriVariables the variables to expand the template * @see HttpEntity */ - void put(String url, @Nullable Object request, Map uriVariables) throws RestClientException; + void put(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** * Creates a new resource by PUTting the given object to URL. @@ -377,7 +377,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @see RestTemplate#setRequestFactory * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory */ - @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) + @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, @Nullable Object... uriVariables) throws RestClientException; /** @@ -399,7 +399,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory */ @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, - Map uriVariables) throws RestClientException; + Map uriVariables) throws RestClientException; /** * Update a resource by PATCHing the given object to the URL, @@ -430,7 +430,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param url the URL * @param uriVariables the variables to expand in the template */ - void delete(String url, Object... uriVariables) throws RestClientException; + void delete(String url, @Nullable Object... uriVariables) throws RestClientException; /** * Delete the resources at the specified URI. @@ -438,7 +438,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param url the URL * @param uriVariables the variables to expand the template */ - void delete(String url, Map uriVariables) throws RestClientException; + void delete(String url, Map uriVariables) throws RestClientException; /** * Delete the resources at the specified URL. @@ -456,7 +456,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param uriVariables the variables to expand in the template * @return the value of the {@code Allow} header */ - Set optionsForAllow(String url, Object... uriVariables) throws RestClientException; + Set optionsForAllow(String url, @Nullable Object... uriVariables) throws RestClientException; /** * Return the value of the {@code Allow} header for the given URI. @@ -465,7 +465,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @param uriVariables the variables to expand in the template * @return the value of the {@code Allow} header */ - Set optionsForAllow(String url, Map uriVariables) throws RestClientException; + Set optionsForAllow(String url, Map uriVariables) throws RestClientException; /** * Return the value of the {@code Allow} header for the given URL. @@ -491,7 +491,7 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @since 3.0.2 */ ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, - Class responseType, Object... uriVariables) throws RestClientException; + Class responseType, @Nullable Object... uriVariables) throws RestClientException; /** * Execute the HTTP method to the given URI template, writing the given request entity to the request, @@ -507,7 +507,7 @@ ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEnti * @since 3.0.2 */ ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, - Class responseType, Map uriVariables) throws RestClientException; + Class responseType, Map uriVariables) throws RestClientException; /** * Execute the HTTP method to the given URI template, writing the given request entity to the request, @@ -544,7 +544,7 @@ ResponseEntity exchange(URI url, HttpMethod method, @Nullable HttpEntity< * @since 3.2 */ ResponseEntity exchange(String url,HttpMethod method, @Nullable HttpEntity requestEntity, - ParameterizedTypeReference responseType, Object... uriVariables) throws RestClientException; + ParameterizedTypeReference responseType, @Nullable Object... uriVariables) throws RestClientException; /** * Execute the HTTP method to the given URI template, writing the given @@ -567,7 +567,7 @@ ResponseEntity exchange(String url,HttpMethod method, @Nullable HttpEntit * @since 3.2 */ ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, - ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException; + ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException; /** * Execute the HTTP method to the given URI template, writing the given @@ -648,7 +648,7 @@ ResponseEntity exchange(RequestEntity requestEntity, ParameterizedType * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor, Object... uriVariables) + @Nullable ResponseExtractor responseExtractor, @Nullable Object... uriVariables) throws RestClientException; /** @@ -663,7 +663,7 @@ ResponseEntity exchange(RequestEntity requestEntity, ParameterizedType * @return an arbitrary object, as returned by the {@link ResponseExtractor} */ @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor, Map uriVariables) + @Nullable ResponseExtractor responseExtractor, Map uriVariables) throws RestClientException; /** diff --git a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java index 6f7b992bdba9..0bd298014abb 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestTemplate.java @@ -330,7 +330,7 @@ public ResponseErrorHandler getErrorHandler() { * @param uriVars the default URI variable values * @since 4.3 */ - public void setDefaultUriVariables(Map uriVars) { + public void setDefaultUriVariables(Map uriVars) { if (this.uriTemplateHandler instanceof DefaultUriBuilderFactory factory) { factory.setDefaultUriVariables(uriVars); } @@ -405,7 +405,7 @@ public void setObservationConvention(ClientRequestObservationConvention observat // GET @Override - public @Nullable T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException { + public @Nullable T getForObject(String url, Class responseType, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor responseExtractor = new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger); @@ -429,7 +429,7 @@ public void setObservationConvention(ClientRequestObservationConvention observat } @Override - public ResponseEntity getForEntity(String url, Class responseType, Object... uriVariables) + public ResponseEntity getForEntity(String url, Class responseType, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); @@ -438,7 +438,7 @@ public ResponseEntity getForEntity(String url, Class responseType, Obj } @Override - public ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) + public ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); @@ -457,12 +457,12 @@ public ResponseEntity getForEntity(URI url, Class responseType) throws // HEAD @Override - public HttpHeaders headForHeaders(String url, Object... uriVariables) throws RestClientException { + public HttpHeaders headForHeaders(String url, @Nullable Object... uriVariables) throws RestClientException { return nonNull(execute(url, HttpMethod.HEAD, null, headersExtractor(), uriVariables)); } @Override - public HttpHeaders headForHeaders(String url, Map uriVariables) throws RestClientException { + public HttpHeaders headForHeaders(String url, Map uriVariables) throws RestClientException { return nonNull(execute(url, HttpMethod.HEAD, null, headersExtractor(), uriVariables)); } @@ -475,7 +475,7 @@ public HttpHeaders headForHeaders(URI url) throws RestClientException { // POST @Override - public @Nullable URI postForLocation(String url, @Nullable Object request, Object... uriVariables) + public @Nullable URI postForLocation(String url, @Nullable Object request, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -484,7 +484,7 @@ public HttpHeaders headForHeaders(URI url) throws RestClientException { } @Override - public @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) + public @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -501,7 +501,7 @@ public HttpHeaders headForHeaders(URI url) throws RestClientException { @Override public @Nullable T postForObject(String url, @Nullable Object request, Class responseType, - Object... uriVariables) throws RestClientException { + @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); HttpMessageConverterExtractor responseExtractor = @@ -511,7 +511,7 @@ public HttpHeaders headForHeaders(URI url) throws RestClientException { @Override public @Nullable T postForObject(String url, @Nullable Object request, Class responseType, - Map uriVariables) throws RestClientException { + Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); HttpMessageConverterExtractor responseExtractor = @@ -531,7 +531,7 @@ public HttpHeaders headForHeaders(URI url) throws RestClientException { @Override public ResponseEntity postForEntity(String url, @Nullable Object request, - Class responseType, Object... uriVariables) throws RestClientException { + Class responseType, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); ResponseExtractor> responseExtractor = responseEntityExtractor(responseType); @@ -540,7 +540,7 @@ public ResponseEntity postForEntity(String url, @Nullable Object request, @Override public ResponseEntity postForEntity(String url, @Nullable Object request, - Class responseType, Map uriVariables) throws RestClientException { + Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); ResponseExtractor> responseExtractor = responseEntityExtractor(responseType); @@ -560,7 +560,7 @@ public ResponseEntity postForEntity(URI url, @Nullable Object request, Cl // PUT @Override - public void put(String url, @Nullable Object request, Object... uriVariables) + public void put(String url, @Nullable Object request, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -568,7 +568,7 @@ public void put(String url, @Nullable Object request, Object... uriVariables) } @Override - public void put(String url, @Nullable Object request, Map uriVariables) + public void put(String url, @Nullable Object request, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -586,7 +586,7 @@ public void put(URI url, @Nullable Object request) throws RestClientException { @Override public @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, - Object... uriVariables) throws RestClientException { + @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); HttpMessageConverterExtractor responseExtractor = @@ -596,7 +596,7 @@ public void put(URI url, @Nullable Object request) throws RestClientException { @Override public @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, - Map uriVariables) throws RestClientException { + Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); HttpMessageConverterExtractor responseExtractor = @@ -618,12 +618,12 @@ public void put(URI url, @Nullable Object request) throws RestClientException { // DELETE @Override - public void delete(String url, Object... uriVariables) throws RestClientException { + public void delete(String url, @Nullable Object... uriVariables) throws RestClientException { execute(url, HttpMethod.DELETE, null, null, uriVariables); } @Override - public void delete(String url, Map uriVariables) throws RestClientException { + public void delete(String url, Map uriVariables) throws RestClientException { execute(url, HttpMethod.DELETE, null, null, uriVariables); } @@ -636,14 +636,14 @@ public void delete(URI url) throws RestClientException { // OPTIONS @Override - public Set optionsForAllow(String url, Object... uriVariables) throws RestClientException { + public Set optionsForAllow(String url, @Nullable Object... uriVariables) throws RestClientException { ResponseExtractor headersExtractor = headersExtractor(); HttpHeaders headers = execute(url, HttpMethod.OPTIONS, null, headersExtractor, uriVariables); return (headers != null ? headers.getAllow() : Collections.emptySet()); } @Override - public Set optionsForAllow(String url, Map uriVariables) throws RestClientException { + public Set optionsForAllow(String url, Map uriVariables) throws RestClientException { ResponseExtractor headersExtractor = headersExtractor(); HttpHeaders headers = execute(url, HttpMethod.OPTIONS, null, headersExtractor, uriVariables); return (headers != null ? headers.getAllow() : Collections.emptySet()); @@ -661,7 +661,7 @@ public Set optionsForAllow(URI url) throws RestClientException { @Override public ResponseEntity exchange(String url, HttpMethod method, - @Nullable HttpEntity requestEntity, Class responseType, Object... uriVariables) + @Nullable HttpEntity requestEntity, Class responseType, @Nullable Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType); @@ -671,7 +671,7 @@ public ResponseEntity exchange(String url, HttpMethod method, @Override public ResponseEntity exchange(String url, HttpMethod method, - @Nullable HttpEntity requestEntity, Class responseType, Map uriVariables) + @Nullable HttpEntity requestEntity, Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(requestEntity, responseType); @@ -690,7 +690,7 @@ public ResponseEntity exchange(URI url, HttpMethod method, @Nullable Http @Override public ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, - ParameterizedTypeReference responseType, Object... uriVariables) throws RestClientException { + ParameterizedTypeReference responseType, @Nullable Object... uriVariables) throws RestClientException { Type type = responseType.getType(); RequestCallback requestCallback = httpEntityCallback(requestEntity, type); @@ -700,7 +700,7 @@ public ResponseEntity exchange(String url, HttpMethod method, @Nullable H @Override public ResponseEntity exchange(String url, HttpMethod method, @Nullable HttpEntity requestEntity, - ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException { + ParameterizedTypeReference responseType, Map uriVariables) throws RestClientException { Type type = responseType.getType(); RequestCallback requestCallback = httpEntityCallback(requestEntity, type); @@ -779,7 +779,7 @@ else if (ext.getVarsMap() != null) { */ @Override public @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor, Object... uriVariables) throws RestClientException { + @Nullable ResponseExtractor responseExtractor, @Nullable Object... uriVariables) throws RestClientException { URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables); return doExecute(url, uriTemplate, method, requestCallback, responseExtractor); @@ -798,7 +798,7 @@ else if (ext.getVarsMap() != null) { */ @Override public @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, - @Nullable ResponseExtractor responseExtractor, Map uriVariables) + @Nullable ResponseExtractor responseExtractor, Map uriVariables) throws RestClientException { URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables); diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index b49830a09472..6302f8d176da 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.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. @@ -49,7 +49,7 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { private EncodingMode encodingMode = EncodingMode.TEMPLATE_AND_VALUES; - private @Nullable Map defaultUriVariables; + private @Nullable Map defaultUriVariables; private boolean parsePath = true; @@ -140,7 +140,7 @@ public EncodingMode getEncodingMode() { * with a Map of variables. * @param defaultUriVariables default URI variable values */ - public void setDefaultUriVariables(@Nullable Map defaultUriVariables) { + public void setDefaultUriVariables(@Nullable Map defaultUriVariables) { if (defaultUriVariables != null) { if (this.defaultUriVariables == null) { this.defaultUriVariables = new HashMap<>(defaultUriVariables); @@ -192,12 +192,12 @@ public boolean shouldParsePath() { // UriTemplateHandler @Override - public URI expand(String uriTemplate, Map uriVars) { + public URI expand(String uriTemplate, Map uriVars) { return uriString(uriTemplate).build(uriVars); } @Override - public URI expand(String uriTemplate, Object... uriVars) { + public URI expand(String uriTemplate, @Nullable Object... uriVars) { return uriString(uriTemplate).build(uriVars); } @@ -446,7 +446,7 @@ public URI build(Map uriVars) { } @Override - public URI build(Object... uriVars) { + public URI build(@Nullable Object... uriVars) { if (ObjectUtils.isEmpty(uriVars) && !CollectionUtils.isEmpty(defaultUriVariables)) { return build(Collections.emptyMap()); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java index 238aca79bc87..3c36ed29f35d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriBuilder.java @@ -261,7 +261,7 @@ public interface UriBuilder { * @param uriVariables the map of URI variables * @return the URI */ - URI build(Object... uriVariables); + URI build(@Nullable Object... uriVariables); /** * Build a {@link URI} instance and replaces URI template variables @@ -269,7 +269,7 @@ public interface UriBuilder { * @param uriVariables the map of URI variables * @return the URI */ - URI build(Map uriVariables); + URI build(Map uriVariables); /** * Return a String representation of the URI by concatenating all URI diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java index c8ae65a0ace5..ee1e4bdc58ca 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponents.java @@ -148,7 +148,7 @@ public final UriComponents encode() { * @param uriVariables the map of URI variables * @return the expanded URI components */ - public final UriComponents expand(Map uriVariables) { + public final UriComponents expand(Map uriVariables) { Assert.notNull(uriVariables, "'uriVariables' must not be null"); return expandInternal(new MapTemplateVariables(uriVariables)); } @@ -159,7 +159,7 @@ public final UriComponents expand(Map uriVariables) { * @param uriVariableValues the URI variable values * @return the expanded URI components */ - public final UriComponents expand(Object... uriVariableValues) { + public final UriComponents expand(@Nullable Object... uriVariableValues) { Assert.notNull(uriVariableValues, "'uriVariableValues' must not be null"); return expandInternal(new VarArgsTemplateVariables(uriVariableValues)); } @@ -324,9 +324,9 @@ public interface UriTemplateVariables { */ private static class MapTemplateVariables implements UriTemplateVariables { - private final Map uriVariables; + private final Map uriVariables; - public MapTemplateVariables(Map uriVariables) { + public MapTemplateVariables(Map uriVariables) { this.uriVariables = uriVariables; } @@ -347,7 +347,7 @@ private static class VarArgsTemplateVariables implements UriTemplateVariables { private final Iterator valueIterator; - public VarArgsTemplateVariables(Object... uriVariableValues) { + public VarArgsTemplateVariables(@Nullable Object... uriVariableValues) { this.valueIterator = Arrays.asList(uriVariableValues).iterator(); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index 8aa36ccf1962..c1d9930043ac 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -337,17 +337,17 @@ public UriComponents buildAndExpand(Map uriVariables) { * @param uriVariableValues the URI variable values * @return the URI components with expanded values */ - public UriComponents buildAndExpand(Object... uriVariableValues) { + public UriComponents buildAndExpand(@Nullable Object... uriVariableValues) { return build().expand(uriVariableValues); } @Override - public URI build(Object... uriVariables) { + public URI build(@Nullable Object... uriVariables) { return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri(); } @Override - public URI build(Map uriVariables) { + public URI build(Map uriVariables) { return buildInternal(EncodingHint.ENCODE_TEMPLATE).expand(uriVariables).toUri(); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplateHandler.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplateHandler.java index 0b7d06504b26..1cd17707e151 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplateHandler.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplateHandler.java @@ -19,6 +19,8 @@ import java.net.URI; import java.util.Map; +import org.jspecify.annotations.Nullable; + /** * Defines methods for expanding a URI template with variables. * @@ -34,7 +36,7 @@ public interface UriTemplateHandler { * @param uriVariables variable values * @return the created URI instance */ - URI expand(String uriTemplate, Map uriVariables); + URI expand(String uriTemplate, Map uriVariables); /** * Expand the given URI template with an array of URI variables. @@ -42,6 +44,6 @@ public interface UriTemplateHandler { * @param uriVariables variable values * @return the created URI instance */ - URI expand(String uriTemplate, Object... uriVariables); + URI expand(String uriTemplate, @Nullable Object... uriVariables); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java index 9362697bf0aa..de159baad4dc 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriUtils.java @@ -325,7 +325,7 @@ public static String encode(String source, Charset charset) { * @return the encoded String * @since 5.0 */ - public static Map encodeUriVariables(Map uriVariables) { + public static Map encodeUriVariables(Map uriVariables) { Map result = CollectionUtils.newLinkedHashMap(uriVariables.size()); uriVariables.forEach((key, value) -> { String stringValue = (value != null ? value.toString() : ""); @@ -341,7 +341,7 @@ public static Map encodeUriVariables(Map uriVariables * @return the encoded String * @since 5.0 */ - public static Object[] encodeUriVariables(Object... uriVariables) { + public static Object[] encodeUriVariables(@Nullable Object... uriVariables) { return Arrays.stream(uriVariables) .map(value -> { String stringValue = (value != null ? value.toString() : ""); diff --git a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt index cefc9542eb42..61ebf19faa1a 100644 --- a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt +++ b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt @@ -36,7 +36,7 @@ import kotlin.reflect.KClass * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.getForObject(url: String, vararg uriVariables: Any): T = +inline fun RestOperations.getForObject(url: String, vararg uriVariables: Any?): T = getForObject(url, T::class.java as Class<*>, *uriVariables) as T /** @@ -92,7 +92,7 @@ inline fun RestOperations.getForEntity(url: URI): ResponseEntit * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.getForEntity(url: String, vararg uriVariables: Any): ResponseEntity = +inline fun RestOperations.getForEntity(url: String, vararg uriVariables: Any?): ResponseEntity = getForEntity(url, T::class.java, *uriVariables) /** @@ -119,7 +119,7 @@ inline fun RestOperations.getForEntity(url: String, uriVariable */ @Throws(RestClientException::class) inline fun RestOperations.patchForObject(url: String, request: Any? = null, - vararg uriVariables: Any): T = + vararg uriVariables: Any?): T = patchForObject(url, request, T::class.java as Class<*>, *uriVariables) as T /** @@ -161,7 +161,7 @@ inline fun RestOperations.patchForObject(url: URI, request: Any? = n */ @Throws(RestClientException::class) inline fun RestOperations.postForObject(url: String, request: Any? = null, - vararg uriVariables: Any): T = + vararg uriVariables: Any?): T = postForObject(url, request, T::class.java as Class<*>, *uriVariables) as T /** @@ -205,7 +205,7 @@ inline fun RestOperations.postForObject(url: URI, request: Any? = nu */ @Throws(RestClientException::class) inline fun RestOperations.postForEntity(url: String, request: Any? = null, - vararg uriVariables: Any): ResponseEntity = + vararg uriVariables: Any?): ResponseEntity = postForEntity(url, request, T::class.java, *uriVariables) /** @@ -248,7 +248,7 @@ inline fun RestOperations.postForEntity(url: URI, request: Any? */ @Throws(RestClientException::class) inline fun RestOperations.exchange(url: String, method: HttpMethod, - requestEntity: HttpEntity<*>? = null, vararg uriVariables: Any): ResponseEntity = + requestEntity: HttpEntity<*>? = null, vararg uriVariables: Any?): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}, *uriVariables) /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java index 491ea6b6b7ce..57328d531783 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -120,7 +120,7 @@ public T getNativeRequest() { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder get(String urlTemplate, Object... uriVars) { + public static BaseBuilder get(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.GET, urlTemplate, uriVars); } @@ -130,7 +130,7 @@ public static BaseBuilder get(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder head(String urlTemplate, Object... uriVars) { + public static BaseBuilder head(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.HEAD, urlTemplate, uriVars); } @@ -140,7 +140,7 @@ public static BaseBuilder head(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder post(String urlTemplate, Object... uriVars) { + public static BodyBuilder post(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.POST, urlTemplate, uriVars); } @@ -151,7 +151,7 @@ public static BodyBuilder post(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder put(String urlTemplate, Object... uriVars) { + public static BodyBuilder put(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.PUT, urlTemplate, uriVars); } @@ -161,7 +161,7 @@ public static BodyBuilder put(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BodyBuilder patch(String urlTemplate, Object... uriVars) { + public static BodyBuilder patch(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.PATCH, urlTemplate, uriVars); } @@ -171,7 +171,7 @@ public static BodyBuilder patch(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder delete(String urlTemplate, Object... uriVars) { + public static BaseBuilder delete(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.DELETE, urlTemplate, uriVars); } @@ -181,7 +181,7 @@ public static BaseBuilder delete(String urlTemplate, Object... uriVars) { * @param uriVars zero or more URI variables * @return the created builder */ - public static BaseBuilder options(String urlTemplate, Object... uriVars) { + public static BaseBuilder options(String urlTemplate, @Nullable Object... uriVars) { return method(HttpMethod.OPTIONS, urlTemplate, uriVars); } @@ -206,7 +206,7 @@ public static BodyBuilder method(HttpMethod method, URI url) { * @param vars variables to expand into the template * @return the created builder */ - public static BodyBuilder method(HttpMethod method, String uri, Object... vars) { + public static BodyBuilder method(HttpMethod method, String uri, @Nullable Object... vars) { return method(method, toUri(uri, vars)); } @@ -221,12 +221,12 @@ public static BodyBuilder method(HttpMethod method, String uri, Object... vars) * @deprecated in favor of {@link #method(HttpMethod, String, Object...)} */ @Deprecated - public static BodyBuilder method(String httpMethod, String uri, Object... vars) { + public static BodyBuilder method(String httpMethod, String uri, @Nullable Object... vars) { Assert.isTrue(StringUtils.hasText(httpMethod), "HTTP method is required."); return new DefaultBodyBuilder(HttpMethod.valueOf(httpMethod), toUri(uri, vars)); } - private static URI toUri(String uri, Object[] vars) { + private static URI toUri(String uri, @Nullable Object[] vars) { return UriComponentsBuilder.fromUriString(uri).buildAndExpand(vars).encode().toUri(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index 86174a9cc40c..9b32b5bae699 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.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. @@ -216,7 +216,7 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { } @Override - public RequestBodySpec uri(String uriTemplate, Object... uriVariables) { + public RequestBodySpec uri(String uriTemplate, @Nullable Object... uriVariables) { UriBuilder uriBuilder = uriBuilderFactory.uriString(uriTemplate); attribute(URI_TEMPLATE_ATTRIBUTE, uriBuilder.toUriString()); return uri(uriBuilder.build(uriVariables)); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index 69e07aebf589..a7f6c528dfb5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -28,6 +28,7 @@ import io.micrometer.observation.ObservationConvention; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -391,7 +392,7 @@ interface UriSpec> { * If a {@link UriBuilderFactory} was configured for the client (for example, * with a base URI) it will be used to expand the URI template. */ - S uri(String uri, Object... uriVariables); + S uri(String uri, @Nullable Object... uriVariables); /** * Specify the URI for the request using a URI template and URI variables. diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java index aee261e14c83..8ca609e51944 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/AbstractWebSocketClient.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. @@ -61,7 +61,7 @@ public abstract class AbstractWebSocketClient implements WebSocketClient { @Override public CompletableFuture execute(WebSocketHandler webSocketHandler, - String uriTemplate, Object... uriVars) { + String uriTemplate, @Nullable Object... uriVars) { Assert.notNull(uriTemplate, "'uriTemplate' must not be null"); URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java index ade1372af788..5bc8f0f98ae0 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/ConnectionManagerSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 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. @@ -20,6 +20,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.SmartLifecycle; import org.springframework.web.util.UriComponentsBuilder; @@ -52,7 +53,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle { /** * Constructor with a URI template and variables. */ - public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) { + public ConnectionManagerSupport(String uriTemplate, @Nullable Object... uriVariables) { this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri(); } diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java index 79df88e23135..3590fe78415f 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketClient.java @@ -46,7 +46,7 @@ public interface WebSocketClient { * @since 6.0 */ CompletableFuture execute(WebSocketHandler webSocketHandler, - String uriTemplate, Object... uriVariables); + String uriTemplate, @Nullable Object... uriVariables); /** * Execute a handshake request to the given url and handle the resulting diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java index 4dff63531cb5..1de144bc6848 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/WebSocketConnectionManager.java @@ -53,7 +53,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport { * Constructor with the client to use and a handler to handle messages with. */ public WebSocketConnectionManager(WebSocketClient client, - WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) { + WebSocketHandler webSocketHandler, String uriTemplate, @Nullable Object... uriVariables) { super(uriTemplate, uriVariables); this.client = client; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java index 028cb60c4a5a..2c515bfe55ae 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/AnnotatedEndpointConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 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. @@ -51,13 +51,13 @@ public class AnnotatedEndpointConnectionManager extends ConnectionManagerSupport private volatile @Nullable Session session; - public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, Object... uriVariables) { + public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, @Nullable Object... uriVariables) { super(uriTemplate, uriVariables); this.endpoint = endpoint; this.endpointProvider = null; } - public AnnotatedEndpointConnectionManager(Class endpointClass, String uriTemplate, Object... uriVariables) { + public AnnotatedEndpointConnectionManager(Class endpointClass, String uriTemplate, @Nullable Object... uriVariables) { super(uriTemplate, uriVariables); this.endpoint = null; this.endpointProvider = new BeanCreatingHandlerProvider<>(endpointClass); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java index edebfdcb492c..c5ca86fb0a90 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/client/standard/EndpointConnectionManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 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. @@ -62,14 +62,14 @@ public class EndpointConnectionManager extends ConnectionManagerSupport implemen private volatile @Nullable Session session; - public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, Object... uriVariables) { + public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, @Nullable Object... uriVariables) { super(uriTemplate, uriVariables); Assert.notNull(endpoint, "endpoint must not be null"); this.endpoint = endpoint; this.endpointProvider = null; } - public EndpointConnectionManager(Class endpointClass, String uriTemplate, Object... uriVars) { + public EndpointConnectionManager(Class endpointClass, String uriTemplate, @Nullable Object... uriVars) { super(uriTemplate, uriVars); Assert.notNull(endpointClass, "endpointClass must not be null"); this.endpoint = null; diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java index 28b020759dd2..18efe57df512 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/messaging/WebSocketStompClient.java @@ -235,7 +235,7 @@ public boolean isRunning() { * @return a CompletableFuture for access to the session when ready for use * @since 6.0 */ - public CompletableFuture connectAsync(String url, StompSessionHandler handler, Object... uriVars) { + public CompletableFuture connectAsync(String url, StompSessionHandler handler, @Nullable Object... uriVars) { return connectAsync(url, null, handler, uriVars); } @@ -251,7 +251,7 @@ public CompletableFuture connectAsync(String url, StompSessionHand * @since 6.0 */ public CompletableFuture connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, - StompSessionHandler handler, Object... uriVariables) { + StompSessionHandler handler, @Nullable Object... uriVariables) { return connectAsync(url, handshakeHeaders, null, handler, uriVariables); } @@ -270,7 +270,7 @@ public CompletableFuture connectAsync(String url, @Nullable WebSoc * @since 6.0 */ public CompletableFuture connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders, - @Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) { + @Nullable StompHeaders connectHeaders, StompSessionHandler handler, @Nullable Object... uriVariables) { Assert.notNull(url, "'url' must not be null"); URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri(); diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java index eab7d63758ce..726832bc07f1 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsClient.java @@ -218,7 +218,7 @@ public boolean isRunning() { @Override public CompletableFuture execute( - WebSocketHandler handler, String uriTemplate, Object... uriVars) { + WebSocketHandler handler, String uriTemplate, @Nullable Object... uriVars) { Assert.notNull(uriTemplate, "uriTemplate must not be null"); URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri(); diff --git a/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java b/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java index d6fbc45ea45d..382b22eae4e0 100644 --- a/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java +++ b/spring-websocket/src/test/java/org/springframework/web/socket/client/WebSocketConnectionManagerTests.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.concurrent.CompletableFuture; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.Lifecycle; @@ -110,7 +111,7 @@ public boolean isRunning() { @Override public CompletableFuture execute(WebSocketHandler handler, - String uriTemplate, Object... uriVars) { + String uriTemplate, @Nullable Object... uriVars) { URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri(); return execute(handler, null, uri);