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

JSR-303 @Valid validation throws BindException instead of MethodArgumentNotValidException [SPR-10157] #14790

Closed
spring-projects-issues opened this issue Jan 9, 2013 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jan 9, 2013

Mohammad Kurabi opened SPR-10157 and commented

When using @Valid without @RequestBody on request parameter, the validation throws a BindException instead of a MethodArgumentNotValidException when the object fails validation.

Noticed this issue when I realized my global exception handler that handles MethodArgumentNotValidException was not being invoked. I beleive this should be consistent and should throw MethodArgumentNotValidException when validation fails.

Example:
https://gist.github.com/c658b7f749df09b5465e


Affects: 3.2 GA

Reference URL: https://gist.github.com/c658b7f749df09b5465e

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jan 10, 2013

Rossen Stoyanchev commented

These are actually intentionally different exceptions. @ModelAttribute, which is assumed by default if no other annotation is present, goes through data binding and validation, and raises BindException to indicate a failure with binding request properties or validating the resulting values. @RequestBody, on the other hand converts the body of the request via HttpMessageConverter, validates it and raises various conversion related exceptions or a MethodArgumentNotValidexception if validation fails. In most cases a MethodArgumentNotValidException can be handled generically (e.g. via @ExceptionHandler method) while BindException is very often handled individually in each controller method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants