From 0101945708a3c92609a735fb6b70f38217ff0c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Deleuze?= Date: Mon, 19 Aug 2024 10:46:47 +0200 Subject: [PATCH] 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 --- .../web/reactive/server/DefaultWebTestClient.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 7e23910cf33..a76b9bc972b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -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. @@ -66,6 +66,7 @@ import org.springframework.web.util.UriBuilderFactory; * @author Rossen Stoyanchev * @author Sam Brannen * @author MichaƂ Rowicki + * @author Sebastien Deleuze * @since 5.0 */ class DefaultWebTestClient implements WebTestClient { @@ -490,7 +491,14 @@ class DefaultWebTestClient implements WebTestClient { @Override public FluxExchangeResult returnResult(ParameterizedTypeReference elementTypeRef) { - Flux body = this.response.bodyToFlux(elementTypeRef); + Flux 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); }