Skip to content

Commit 79795c8

Browse files
committed
Avoid compilation error on WebTestClient without Hamcrest
This commit removes JSpecify (TYPE_USE) annotations on org.hamcrest.Matcher parameters to prevent a related "Cannot attach type annotations" error when Hamcrest (optional dependency) is not in the classpath with Java > 22. Closes gh-35666
1 parent 83edf6a commit 79795c8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.function.Function;
2727

2828
import org.hamcrest.Matcher;
29+
import org.jspecify.annotations.NonNull;
30+
import org.jspecify.annotations.NullUnmarked;
2931
import org.jspecify.annotations.Nullable;
3032
import org.reactivestreams.Publisher;
3133

@@ -956,14 +958,16 @@ interface BodySpec<B, S extends BodySpec<B, S>> {
956958
* Assert the extracted body with a {@link Matcher}.
957959
* @since 5.1
958960
*/
959-
<T extends S> T value(Matcher<? super @Nullable B> matcher);
961+
@NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath
962+
<T extends S> T value(Matcher<? super B> matcher);
960963

961964
/**
962965
* Transform the extracted the body with a function, for example, extracting a
963966
* property, and assert the mapped value with a {@link Matcher}.
964967
* @since 5.1
965968
*/
966-
<T extends S, R> T value(Function<@Nullable B, @Nullable R> bodyMapper, Matcher<? super @Nullable R> matcher);
969+
@NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath
970+
<T extends S, R> T value(@NonNull Function<@Nullable B, @Nullable R> bodyMapper, Matcher<? super R> matcher);
967971

968972
/**
969973
* Assert the extracted body with a {@link Consumer}.

0 commit comments

Comments
 (0)