Skip to content

Commit b213344

Browse files
bclozeljhoeller
authored andcommitted
Fix synchronization in ResponseBodyEmitter
See gh-35423 Fixes gh-35466 (cherry picked from commit 20e1149)
1 parent 0a48984 commit b213344

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ public void send(Object object) throws IOException {
201201
* @throws java.lang.IllegalStateException wraps any other errors
202202
*/
203203
public void send(Object object, @Nullable MediaType mediaType) throws IOException {
204-
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
205-
(this.failure != null ? " with error: " + this.failure : ""));
206204
this.writeLock.lock();
207205
try {
206+
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
207+
(this.failure != null ? " with error: " + this.failure : ""));
208208
if (this.handler != null) {
209209
try {
210210
this.handler.send(object, mediaType);
@@ -235,10 +235,10 @@ public void send(Object object, @Nullable MediaType mediaType) throws IOExceptio
235235
* @since 6.0.12
236236
*/
237237
public void send(Set<DataWithMediaType> items) throws IOException {
238-
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
239-
(this.failure != null ? " with error: " + this.failure : ""));
240238
this.writeLock.lock();
241239
try {
240+
Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" +
241+
(this.failure != null ? " with error: " + this.failure : ""));
242242
sendInternal(items);
243243
}
244244
finally {

0 commit comments

Comments
 (0)