Skip to content

ex.getPropertyName() is not initialized in ResponseEntityExceptionHandler#handleTypeMismatch #29959

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
grundtein opened this issue Feb 12, 2023 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@grundtein
Copy link

https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseEntityExceptionHandler.java

Method:handleTypeMismatch

Object[] args = {ex.getPropertyName(), ex.getValue()};
String defaultDetail = "Failed to convert '" + args[0] + "' with value: '" + args[1] + "'";

If exception type is MethodArgumentTypeMismatchException,
return value of "ex.getPropertyName()" is null.
Therefore "defaultDetail" is "Failed to convert 'null' with value: 'val'";
But, return value of "ex.getName()" is correct property name.

Probably "TypeMismatchException#initPropertyName()" is not called.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 12, 2023
@rstoyanchev rstoyanchev changed the title spring-webmvc ResponseEntityExceptionHandler#handleTypeMismatch ex.getPropertyName() is null ex.getPropertyName() is not initialized in ResponseEntityExceptionHandler#handleTypeMismatch Feb 14, 2023
@rstoyanchev rstoyanchev self-assigned this Feb 14, 2023
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 14, 2023
@rstoyanchev rstoyanchev added this to the 6.0.5 milestone Feb 14, 2023
@rstoyanchev
Copy link
Contributor

Indeed, as we are using the property name now in the detail message, we should make sure it's initialied. Both handleTypeMismatch and handleConversionNotSupported.

@grundtein
Copy link
Author

Thank you for your confirmation.

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

No branches or pull requests

3 participants