Skip to content

Commit

Permalink
Prevent a leak in WebTestClient
Browse files Browse the repository at this point in the history
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 spring-projectsgh-33389
  • Loading branch information
sdeleuze committed Aug 19, 2024
1 parent d41ca09 commit 0101945
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -66,6 +66,7 @@
* @author Rossen Stoyanchev
* @author Sam Brannen
* @author Michał Rowicki
* @author Sebastien Deleuze
* @since 5.0
*/
class DefaultWebTestClient implements WebTestClient {
Expand Down Expand Up @@ -490,7 +491,14 @@ public <T> FluxExchangeResult<T> returnResult(Class<T> elementClass) {

@Override
public <T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementTypeRef) {
Flux<T> body = this.response.bodyToFlux(elementTypeRef);
Flux<T> body;
if (elementTypeRef.getType().equals(Void.class)) {
this.response.releaseBody().block();
body = Flux.empty();
}
else {
body = this.response.bodyToFlux(elementTypeRef);
}
return new FluxExchangeResult<>(this.exchangeResult, body);
}

Expand Down

0 comments on commit 0101945

Please sign in to comment.