Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify and log that return value of HandlerMethod is ignored if reason of @ResponseStatus present #31121

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
/**
* The <em>reason</em> to be used for the response.
* <p>Defaults to an empty string which will be ignored. Set the reason to a
* non-empty value to have it used for the response.
* non-empty value to have it used for the response, please note that
* return value of the annotated method will be ignored in this case.
* @see jakarta.servlet.http.HttpServletResponse#sendError(int, String)
*/
String reason() default "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ private void evaluateResponseStatus() {

this.responseStatus = annotation.code();
this.responseStatusReason = resolvedReason;
if (StringUtils.hasText(this.responseStatusReason) && getMethod().getReturnType() != void.class) {
logger.warn("Return value of method [" + getMethod() + "] will be ignored since reason of @ResponseStatus present, please consider changing the return type to void");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public void invokeAndHandle(ServletWebRequest webRequest, ModelAndViewContainer
}
}
else if (StringUtils.hasText(getResponseStatusReason())) {
if (logger.isDebugEnabled()) {
logger.debug("Return value [" + returnValue + "] of method [" + getMethod() + "] is ignored since reason of @ResponseStatus will be used for response");
}
mavContainer.setRequestHandled(true);
return;
}
Expand Down