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

Resolve property-dependent parameter names for exception messages #32462

Closed
wants to merge 4 commits into from

Conversation

andrea-mauro
Copy link
Contributor

When named value method arguments are defined through placeholders or SpeL and an exception is thrown because the required parameter is missing or can't be converted, the exception message references the placeholder instead of the resolved named value. Example:

Required header '${systemProperty}' is not present.

This PR enhances the error message by passing the resolved parameter name to the error handlers, so that the exception thrown is more relevant.

Closes #32323

Prior to this commit when a required parameter defined as a property or expression placeholder was missing, the exception thrown would refer to the placeholder instead of the resolved name.

See spring-projectsgh-32323
Prior to this commit when a non-required parameter defined as a property or expression placeholder was missing and the value couldn't be returned as null due to its type being primitive, the exception thrown would refer to the placeholder instead of the resolved name.

See spring-projectsgh-32323
…r message

Prior to this commit when a required parameter with conversion defined as a property or expression placeholder was missing, the exception thrown would refer to the placeholder instead of the resolved name.

See spring-projectsgh-32323
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 16, 2024
@sbrannen sbrannen added in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) labels Mar 16, 2024
@simonbasle simonbasle self-assigned this Mar 18, 2024
@simonbasle simonbasle added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 18, 2024
@simonbasle simonbasle added this to the 6.2.0-M1 milestone Mar 18, 2024
Copy link
Contributor

@simonbasle simonbasle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but IIRC there's a similar pattern in spring-webflux as well (in AbstractNamedValueArgumentResolver). can you cover that one as well?

…gValue and handleNullValue to improve error message

Prior to this commit when an error occurred related to a property or expression placeholder, the exception thrown would refer to the placeholder instead of the resolved name.

See spring-projectsgh-32323
@andrea-mauro
Copy link
Contributor Author

@simonbasle The occurrence in spring-webflux is now covered as well. Please take a look.

@simonbasle simonbasle changed the title Property dependent parameters are not resolved in Exception message when missing Resolve property-dependent parameter names for exception messages Mar 20, 2024
@andrea-mauro andrea-mauro deleted the gh-32323 branch March 20, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property dependent @RequestParam parameters are not resolved on bad request
4 participants