Javadoc for ModelAttributeMethodProcessor.validateIfApplicable is misleading [SPR-12655] #17256
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
status: backported
An issue that has been backported to maintenance branches
type: task
A general task
Milestone
Lukas Hinsch opened SPR-12655 and commented
Update:
The javadoc for ModelAttributeMethodProcessor.validateIfApplicable claims that validation is triggered by checking for annotation of type javax.validation.Valid, whereas the actual implementation looks for annotation type names starting with "Valid" to allow for additional annotations (see comment below).
To avoid confusion the javadoc should be adjusted to reflect this behavior (such as "The default implementation checks for annotations starting with "Valid" to cover {
@code
javax.validation.Valid}, {@code
org.springframework.validation.annotation.Validated} and others.")
Was originally:
When checking for annotation javax.validation.Valid the code only checks if the simple class name starts with "Valid".
I was playing around with controller aspects in combination with custom annotations that by accident also started with "Valid" and it took me a while to understand why bean validation was triggered by my custom annotation.
So I think in: ModelAttributeMethodProcessor:162
the code should be changed from
to something like
(https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java#L162)
Affects: 3.2.13, 4.1.4
Referenced from: commits 9a7871f, 7585be8, d77af71, 186fef6, 25644db, 7191050
Backported to: 3.2.14
The text was updated successfully, but these errors were encountered: