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 361bf3fcdd1..5b895ec86e5 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 @@ -26,6 +26,8 @@ import java.util.function.Consumer; import java.util.function.Function; import org.hamcrest.Matcher; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.NullUnmarked; import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; @@ -956,14 +958,16 @@ public interface WebTestClient { * Assert the extracted body with a {@link Matcher}. * @since 5.1 */ - T value(Matcher matcher); + @NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath + T value(Matcher matcher); /** * Transform the extracted the body with a function, for example, extracting a * property, and assert the mapped value with a {@link Matcher}. * @since 5.1 */ - T value(Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher); + @NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath + T value(@NonNull Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher); /** * Assert the extracted body with a {@link Consumer}.