From 80b1de20eec24f1809601e9a7b4868e9bd44f63b Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Tue, 5 Aug 2025 11:26:34 +0200 Subject: [PATCH] Add nullability annotations to module/spring-boot-restclient-test See gh-46587 --- .../boot/restclient/test/MockServerRestClientCustomizer.java | 4 +++- .../restclient/test/MockServerRestTemplateCustomizer.java | 4 +++- .../restclient/test/RootUriRequestExpectationManager.java | 2 +- .../springframework/boot/restclient/test/package-info.java | 3 +++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizer.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizer.java index 74956567a7a..d357761f6bc 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizer.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestClientCustomizer.java @@ -21,6 +21,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.boot.restclient.RestClientCustomizer; import org.springframework.http.client.BufferingClientHttpRequestFactory; @@ -133,7 +135,7 @@ public class MockServerRestClientCustomizer implements RestClientCustomizer { return this.expectationManagers; } - public MockRestServiceServer getServer(RestClient.Builder restClientBuilder) { + public @Nullable MockRestServiceServer getServer(RestClient.Builder restClientBuilder) { return this.servers.get(restClientBuilder); } diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizer.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizer.java index 449a7b6a585..694e1781c1d 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizer.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/MockServerRestTemplateCustomizer.java @@ -21,6 +21,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.boot.restclient.RestTemplateBuilder; import org.springframework.boot.restclient.RestTemplateCustomizer; @@ -147,7 +149,7 @@ public class MockServerRestTemplateCustomizer implements RestTemplateCustomizer return this.expectationManagers; } - public MockRestServiceServer getServer(RestTemplate restTemplate) { + public @Nullable MockRestServiceServer getServer(RestTemplate restTemplate) { return this.servers.get(restTemplate); } diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java index bc11307b388..ba9b00755c5 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/RootUriRequestExpectationManager.java @@ -158,7 +158,7 @@ public class RootUriRequestExpectationManager implements RequestExpectationManag RequestExpectationManager expectationManager) { Assert.notNull(restTemplate, "'restTemplate' must not be null"); UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); - if (templateHandler instanceof RootUriTemplateHandler rootHandler) { + if (templateHandler instanceof RootUriTemplateHandler rootHandler && rootHandler.getRootUri() != null) { return new RootUriRequestExpectationManager(rootHandler.getRootUri(), expectationManager); } return expectationManager; diff --git a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/package-info.java b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/package-info.java index 517a2c65020..a5f2c2629ae 100644 --- a/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/package-info.java +++ b/module/spring-boot-restclient-test/src/main/java/org/springframework/boot/restclient/test/package-info.java @@ -17,4 +17,7 @@ /** * RestClient and RestTemplate test utilities. */ +@NullMarked package org.springframework.boot.restclient.test; + +import org.jspecify.annotations.NullMarked;