From c49d5dc860a10c2d03aba781bf0b7987ea8ae9cf Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Thu, 22 Jan 2026 14:17:13 +0000 Subject: [PATCH] Handle early exception from AsynchronousFileChannel#write Closes gh-36184 --- .../springframework/core/io/buffer/DataBufferUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java index 9b9d4b9f79c..85a540c9e80 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java @@ -1205,7 +1205,13 @@ public abstract class DataBufferUtils { long pos = this.position.get(); Attachment attachment = new Attachment(byteBuffer, dataBuffer, iterator); this.writing.set(true); - this.channel.write(byteBuffer, pos, attachment, this); + try { + this.channel.write(byteBuffer, pos, attachment, this); + } + catch (RuntimeException ex) { + // If the exception escapes, route it to the failure handler + failed(ex, attachment); + } } }