From 20e1149dde7ff042154e4098d49939a886661c3e Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Fri, 12 Sep 2025 09:12:33 +0200 Subject: [PATCH] Fix synchronization in ResponseBodyEmitter See gh-35423 Fixes gh-35466 --- .../mvc/method/annotation/ResponseBodyEmitter.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java index f7a3aa218d3..5a368b5d994 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitter.java @@ -198,10 +198,10 @@ public class ResponseBodyEmitter { * @throws java.lang.IllegalStateException wraps any other errors */ public void send(Object object, @Nullable MediaType mediaType) throws IOException { - Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + - (this.failure != null ? " with error: " + this.failure : "")); this.writeLock.lock(); try { + Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + + (this.failure != null ? " with error: " + this.failure : "")); if (this.handler != null) { try { this.handler.send(object, mediaType); @@ -232,10 +232,10 @@ public class ResponseBodyEmitter { * @since 6.0.12 */ public void send(Set items) throws IOException { - Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + - (this.failure != null ? " with error: " + this.failure : "")); this.writeLock.lock(); try { + Assert.state(!this.complete, () -> "ResponseBodyEmitter has already completed" + + (this.failure != null ? " with error: " + this.failure : "")); sendInternal(items); } finally {