Skip to content

Commit 29a76a6

Browse files
committed
Merge branch '6.2.x'
# Conflicts: # spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java
2 parents 2b526ef + 4b7cf85 commit 29a76a6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
* into memory, thus allowing for multiple invocations of {@link #getBody()}.
3232
*
3333
* @author Arjen Poutsma
34+
* @author Juergen Hoeller
3435
* @since 3.1
3536
*/
3637
final class BufferingClientHttpResponseWrapper implements ClientHttpResponse {
3738

3839
private final ClientHttpResponse response;
3940

40-
private byte @Nullable [] body;
41+
private volatile byte @Nullable [] body;
4142

4243

4344
BufferingClientHttpResponseWrapper(ClientHttpResponse response) {
@@ -62,10 +63,17 @@ public HttpHeaders getHeaders() {
6263

6364
@Override
6465
public InputStream getBody() throws IOException {
65-
if (this.body == null) {
66-
this.body = StreamUtils.copyToByteArray(this.response.getBody());
66+
byte[] body = this.body;
67+
if (body == null) {
68+
synchronized (this) {
69+
body = this.body;
70+
if (body == null) {
71+
body = StreamUtils.copyToByteArray(this.response.getBody());
72+
this.body = body;
73+
}
74+
}
6775
}
68-
return new ByteArrayInputStream(this.body);
76+
return new ByteArrayInputStream(body);
6977
}
7078

7179
@Override

0 commit comments

Comments
 (0)