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

Extending DefaultErrorAttributes and overriding getErrorAttributes() gets called twice #41732

Closed
hsteinmueller opened this issue Aug 8, 2024 · 0 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@hsteinmueller
Copy link

hsteinmueller commented Aug 8, 2024

In Version 3.3.1 60b7e6c got merged.

Implementing custom logic for an error response is done by extending DefaultErrorAttributes, overriding getErrorAttributes() and changing the map returned by super.getErrorAttributes(request, options).

I think it does not behave correctly anymore since this change, because now getErrorAttributes() is called twice - on the first call the options only include STATUS and on the second call the options are ErrorAttributeOptions.defaults() (or whatever is configured), see: 60b7e6c#diff-b4233363b899b2fb4ab8045726ed3e9d6d04c766cb363c2973c137750b340b62R150-R151

When using custom logic this may lead to a NPE when the map unexpectedly only contains "status" on the first call.

It still works correctly for the non-reactive version where getErrorAttributes() is only called once when overriden.

We could handle the first call ourselves by discarding it when the options only include STATUS but I don't think that's the desired solution.

Simple Test-Project: https://github.com/hsteinmueller/spring-error-attributes-bug/blob/master/error-attributes-demo-reactive/src/main/java/org/example/errorattributesdemoreactive/CustomErrorAttributes.java

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 8, 2024
@scottfrederick scottfrederick added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 8, 2024
@scottfrederick scottfrederick added this to the 3.2.x milestone Aug 8, 2024
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed type: bug A general bug labels Aug 12, 2024
@philwebb philwebb self-assigned this Aug 21, 2024
@philwebb philwebb modified the milestones: 3.2.x, 3.2.9 Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants