-
Notifications
You must be signed in to change notification settings - Fork 37.7k
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
Avoid exceptions when evaluating validation hints #26787
Avoid exceptions when evaluating validation hints #26787
Conversation
Prior to this commit, evaluating validation hints for @javax.validation.Valid caused exceptions being raised when getting the value of this annotation, which does not exist. Bypassing AnnotationUtils.getValue() in those cases can improve performance by avoiding the cost incurred by raising exceptions.
* @param ann the annotation (potentially a validation annotation) | ||
* @return the validation hints to apply (possibly an empty array), | ||
* or {@code null} if this annotation does not trigger any validation | ||
* @since 5.3.6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be 5.3.7 now - let me know if I should add that.
Hey @dreis2211 it's indeed worth handling the common |
@jhoeller Thanks for the review. I just committed the requested changes. |
spring-context/src/main/java/org/springframework/validation/ValidationUtils.java
Outdated
Show resolved
Hide resolved
@dreis2211 I can see |
@snicoll Should be fixed - I was a bit overly ambitious and wanted to optimize the custom |
Prior to this commit, evaluating validation hints for @javax.validation.Valid caused exceptions being raised when getting the value of this annotation, which does not exist. Bypassing AnnotationUtils.getValue() in those cases can improve performance by avoiding the cost incurred by raising exceptions. See gh-26787
Thanks for the follow-up Christoph. |
Prior to this commit, evaluating validation hints for @javax.validation.Valid caused exceptions being raised when getting the value of this annotation, which does not exist. Bypassing AnnotationUtils.getValue() in those cases can improve performance by avoiding the cost incurred by raising exceptions. See spring-projectsgh-26787
Prior to this commit, evaluating validation hints for @javax.validation.Valid caused exceptions being raised when getting the value of this annotation, which does not exist. Bypassing AnnotationUtils.getValue() in those cases can improve performance by avoiding the cost incurred by raising exceptions. See spring-projectsgh-26787
Hi,
we noticed in one of our loadtests that a substantial amount of "hidden"
NoSuchMethodException
s is being thrown when using@javax.validation.Valid
on controller methods.This is caused by calling
AnnotationUtils.getValue()
on this annotation, which has no such property. This PR bypasses the annotation utility call. I also took the freedom to refactor this logic into a common place inValidationUtils
to avoid copy-paste throughout the different modules.An isolated JMH benchmark shows the following results when dealing with
@Valid
:As a workaround you can use
org.springframework.validation.annotation.Validated
of course, but I would prefer not to have such a drawback when usingjavax.validation.Valid
.Let me know what you think.
Cheers,
Christoph