Avoid exceptions when evaluating validation hints#26787
Avoid exceptions when evaluating validation hints#26787dreis2211 wants to merge 4 commits intospring-projects:masterfrom
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.
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. |
|
@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
Hi,
we noticed in one of our loadtests that a substantial amount of "hidden"
NoSuchMethodExceptions is being thrown when using@javax.validation.Validon 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 inValidationUtilsto 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.Validatedof course, but I would prefer not to have such a drawback when usingjavax.validation.Valid.Let me know what you think.
Cheers,
Christoph