Skip to content

Custom Exception body empty #33044

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

Closed
bthers-dish opened this issue Jun 17, 2024 · 6 comments
Closed

Custom Exception body empty #33044

bthers-dish opened this issue Jun 17, 2024 · 6 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)

Comments

@bthers-dish
Copy link

bthers-dish commented Jun 17, 2024

Affects: Spring boot 3.2.4


Since upgrading to Spring boot 3.2.4 from 3.2.3 the Custom exception handler does not send response with the custom message in body.

Spring boot 3.2.3

MockHttpServletResponse:
           Status = 500
    Error message = null
          Headers = [Content-Type:"application/json"]
     Content type = application/json
             Body = {"status":"INTERNAL_SERVER_ERROR","message":"An error occurred."}
    Forwarded URL = null
   Redirected URL = null
          Cookies = []

Spring boot 3.2.4+

MockHttpServletResponse:
           Status = 500
    Error message = null
          Headers = [Content-Type:"application/json"]
     Content type = application/json
             Body = 
    Forwarded URL = null
   Redirected URL = null
          Cookies = []

I have reproduced the issue in this sample project, DeferredDemo.zip. This issue persists in Spring Boot 3.3.0

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 17, 2024
@Meijuh
Copy link

Meijuh commented Jun 17, 2024

Related to the problem here, might be the work done in this issue: #32340.

@bclozel bclozel added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jun 19, 2024
@rstoyanchev rstoyanchev self-assigned this Jun 28, 2024
@rstoyanchev
Copy link
Contributor

The sample doesn't seem to be working as described above. DemoController returns new DeferredResult(). That results in AsyncRequestTimeoutException, which is handled by DemoExceptionHandler but it uses the exception message which is null. I changed it to ""An error occurred." but it works with both 3.2.4 and 3.2.3.

@rstoyanchev rstoyanchev added the status: waiting-for-feedback We need additional information before we can continue label Jun 28, 2024
@bthers-dish
Copy link
Author

It is curious that it is working for you but fails on our systems. I have tested it with both Java 17 and 21.

I added AsyncRequestTimeoutException exception handling to the DemoExceptionHandler and added a test to throw the AsyncRequestTimeoutException. I also set the message of the error response to the exception title.

image

Both tests are still failing with an Unparsable JSON string message due to the response body being empty.
DeferredDemo.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 1, 2024
@rstoyanchev
Copy link
Contributor

The tests are using AsyncListener#onError which typically indicates a network or I/O error after the response is no longer usable. We now protect the response from being used in such cases because Servlet containers recycle the request and response and writing may affect the response for a different request.

If I switch the timeout test on AsyncListener#onTimeout which is what is actually called in case of a timeout, the test passes.

@rstoyanchev rstoyanchev added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jul 3, 2024
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Jul 10, 2024
@spring-projects-issues
Copy link
Collaborator

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.

@spring-projects-issues spring-projects-issues closed this as not planned Won't fix, can't repro, duplicate, stale Jul 17, 2024
@spring-projects-issues spring-projects-issues removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket)
Projects
None yet
Development

No branches or pull requests

5 participants