Skip to content

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

Closed
@hsteinmueller

Description

@hsteinmueller

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

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions