Skip to content

Commit 0101945

Browse files
committed
Prevent a leak in WebTestClient
This commit applies the same kind of processing for Void.class element type in the ParameterizedTypeReference variant of WebTestClient.ResponseSpec#returnResult than in the Class variant. Closes gh-33389
1 parent d41ca09 commit 0101945

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -66,6 +66,7 @@
6666
* @author Rossen Stoyanchev
6767
* @author Sam Brannen
6868
* @author Michał Rowicki
69+
* @author Sebastien Deleuze
6970
* @since 5.0
7071
*/
7172
class DefaultWebTestClient implements WebTestClient {
@@ -490,7 +491,14 @@ public <T> FluxExchangeResult<T> returnResult(Class<T> elementClass) {
490491

491492
@Override
492493
public <T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementTypeRef) {
493-
Flux<T> body = this.response.bodyToFlux(elementTypeRef);
494+
Flux<T> body;
495+
if (elementTypeRef.getType().equals(Void.class)) {
496+
this.response.releaseBody().block();
497+
body = Flux.empty();
498+
}
499+
else {
500+
body = this.response.bodyToFlux(elementTypeRef);
501+
}
494502
return new FluxExchangeResult<>(this.exchangeResult, body);
495503
}
496504

0 commit comments

Comments
 (0)