From 8227032a0fe9b49761aa97d0d3a2d03309010944 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 10 Oct 2022 13:26:46 +0200 Subject: [PATCH] Improve exception message if MultipartParser can not find end of body This commit improves the exception message thrown by MultipartParser when it cannot find the end of the multipart body, by showing in the message what the parser is looking for (CRLF--). Closes gh-28067 --- .../http/codec/multipart/MultipartParser.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java index a17c05e8ec..0def952d78 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java @@ -17,6 +17,7 @@ package org.springframework.http.codec.multipart; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; @@ -602,7 +603,10 @@ final class MultipartParser extends BaseSubscriber { @Override public void onComplete() { if (changeState(this, DisposedState.INSTANCE, null)) { - emitError(new DecodingException("Could not find end of body")); + String msg = "Could not find end of body (␍␊--" + + new String(MultipartParser.this.boundary, StandardCharsets.UTF_8) + + ")"; + emitError(new DecodingException(msg)); } }