Skip to content

Conversation

IMurzich
Copy link
Contributor

@IMurzich IMurzich commented Oct 8, 2025

Fix error when corrupt order of produces media types for @ExceptionHandler.

For example, the following returns xml by default.

@ExceptionHandler(exception = Exception.class,
    produces = {"application/json", "application/xml"})

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 8, 2025
@sbrannen sbrannen changed the title Keep order of produce media types in Exeception handler Retain order of produces media types in @ExceptionHandler Oct 8, 2025
@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue in: web Issues in web modules (web, webmvc, webflux, websocket) labels Oct 8, 2025
@sbrannen
Copy link
Member

sbrannen commented Oct 8, 2025

Hi @IMurzich,

Congratulations on submitting your first PR for the Spring Framework! 👍

However, before we process this PR, we need to take care of the following.

  1. Please explain the error scenario you are attempting to fix.
  2. Please introduce a unit or integration test which fails before the fix and passes after the fix.

Regarding point # 1, I realize you added some text to this issue's description, but it is not fully clear to me what you mean. So, perhaps you can just expound on that.

Thanks

@sbrannen sbrannen marked this pull request as draft October 8, 2025 14:56
@IMurzich
Copy link
Contributor Author

IMurzich commented Oct 8, 2025

Hi @sbrannen,

I've added test. Please check it.

Thanks.

@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 Oct 8, 2025
@IMurzich IMurzich marked this pull request as ready for review October 8, 2025 15:44
@IMurzich
Copy link
Contributor Author

IMurzich commented Oct 8, 2025

Purpose of change:

I have a controller and exception handler in it.

My REST service can return JSON or XML replies.

Therefore I want to return exceptions in JSON or XML too.

Exception handler is annotated with:

@ExceptionHandler(exception = Exception.class, produces = {"application/json", "application/xml"})

And I expect to get JSON response with error (accept=*/*), but I receive XML response because HashSet doesn't retain the order of the produces media types and returns application/xml as the first media type.

@sbrannen sbrannen self-assigned this Oct 10, 2025
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on status: feedback-provided Feedback has been provided labels Oct 10, 2025
@sbrannen sbrannen added this to the 6.2.12 milestone Oct 10, 2025
@sbrannen sbrannen added type: bug A general bug and removed type: enhancement A general enhancement labels Oct 11, 2025
@sbrannen
Copy link
Member

sbrannen commented Oct 11, 2025

@IMurzich, can you please sign off your commits so that the Developer Certificate of Origin (DCO) check passes?

Thanks

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Oct 11, 2025
@bclozel
Copy link
Member

bclozel commented Oct 13, 2025

@IMurzich please sign the DCO. You can do that with by issuing the following commands on your fork:

git amend -s
git push --force

@IMurzich IMurzich force-pushed the fix-exceptionhandler-produces-order branch from cf5eefd to 625a918 Compare October 13, 2025 11:53
Signed-off-by: Igor Murzich <imurzich@gmail.com>
Signed-off-by: Igor Murzich <imurzich@gmail.com>
@IMurzich IMurzich force-pushed the fix-exceptionhandler-produces-order branch from 625a918 to 6057763 Compare October 13, 2025 11:58
@sbrannen sbrannen removed the status: waiting-for-feedback We need additional information before we can continue label Oct 13, 2025
sbrannen pushed a commit that referenced this pull request Oct 13, 2025
Closes gh-35587

Signed-off-by: Igor Murzich <imurzich@gmail.com>
sbrannen added a commit that referenced this pull request Oct 13, 2025
Copy link
Contributor

Fixed via 7699b4a

@github-actions github-actions bot closed this Oct 13, 2025
@sbrannen
Copy link
Member

This has been merged into 6.2.x and main in 7699b4a and slightly revised in 8456cd1.

Thanks for your contribution! 👍

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) type: bug A general bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants