From 3f35c41f176c2a02be95fb40cf5ac1561beff8c3 Mon Sep 17 00:00:00 2001 From: wonyongg <111210881+wonyongg@users.noreply.github.com> Date: Sun, 15 Jun 2025 21:08:21 +0900 Subject: [PATCH 1/3] Remove redundant `toString()` call and trailing "in" from error message The `formatErrorForReturnValue` method in `ServletInvocableHandlerMethod` previously included an unnecessary call to `toString()` and a dangling "in" at the end of the formatted string. Since the surrounding context already provides sufficient information, both the `toString()` call and the `" in"` suffix have been removed to improve clarity. No functional changes. Signed-off-by: wonyongg <111210881+wonyongg@users.noreply.github.com> --- .../mvc/method/annotation/ServletInvocableHandlerMethod.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 643830ff194a..c9903984e75f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -189,8 +189,7 @@ private void disableContentCachingIfNecessary(ServletWebRequest webRequest) { private String formatErrorForReturnValue(@Nullable Object returnValue) { return "Error handling return value=[" + returnValue + "]" + - (returnValue != null ? ", type=" + returnValue.getClass().getName() : "") + - " in " + toString(); + (returnValue != null ? ", type=" + returnValue.getClass().getName() : ""); } /** From ff264255c85380c03406decb9e9015b69d7b7318 Mon Sep 17 00:00:00 2001 From: wonyongg <111210881+wonyongg@users.noreply.github.com> Date: Wed, 18 Jun 2025 18:40:56 +0900 Subject: [PATCH 2/3] Clarify Javadoc for HandlerMethod.toString() Document that HandlerMethod.toString() is used in log and error messages, and that the returned description should typically include the method signature of the underlying handler method for clarity and debugging. Signed-off-by: wonyongg <111210881+wonyongg@users.noreply.github.com> --- .../java/org/springframework/web/method/HandlerMethod.java | 6 ++++++ .../method/annotation/ServletInvocableHandlerMethod.java | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index dd40146d66e4..53a83c7ceb7f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -352,6 +352,12 @@ public int hashCode() { return (this.bean.hashCode() * 31 + super.hashCode()); } + /** + * Returns the description of this handler method. + * This method is used in log and error messages, + * so the returned description should typically include the method signature + * of the underlying handler method for clarity and debugging purposes. + */ @Override public String toString() { return this.description; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index c9903984e75f..643830ff194a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -189,7 +189,8 @@ private void disableContentCachingIfNecessary(ServletWebRequest webRequest) { private String formatErrorForReturnValue(@Nullable Object returnValue) { return "Error handling return value=[" + returnValue + "]" + - (returnValue != null ? ", type=" + returnValue.getClass().getName() : ""); + (returnValue != null ? ", type=" + returnValue.getClass().getName() : "") + + " in " + toString(); } /** From 80adb2a3d0b65909e3b0d75898b3c12c6c05e455 Mon Sep 17 00:00:00 2001 From: WonYong Hwang <111210881+wonyongg@users.noreply.github.com> Date: Wed, 18 Jun 2025 19:15:19 +0900 Subject: [PATCH 3/3] Update spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java Co-authored-by: Sam Brannen <104798+sbrannen@users.noreply.github.com> Signed-off-by: WonYong Hwang <111210881+wonyongg@users.noreply.github.com> --- .../org/springframework/web/method/HandlerMethod.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java index 53a83c7ceb7f..9ee65fcd6a3a 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java @@ -353,10 +353,10 @@ public int hashCode() { } /** - * Returns the description of this handler method. - * This method is used in log and error messages, - * so the returned description should typically include the method signature - * of the underlying handler method for clarity and debugging purposes. + * Returns a concise description of this {@code HandlerMethod}, which is used + * in log and error messages. + *
The description should typically include the method signature of the + * underlying handler method for clarity and debugging purposes. */ @Override public String toString() {