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

Avoid reflecting to obtain validationGroups every time the call is made #32068

Closed
brucelwl opened this issue Jan 20, 2024 · 2 comments
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@brucelwl
Copy link

private Class<?>[] getValidationGroups() {
return ((shouldValidateArguments() || shouldValidateReturnValue()) && this.methodValidator != null ?
this.methodValidator.determineValidationGroups(getBean(), getBridgedMethod()) : EMPTY_GROUPS);
}

can call getValidationGroups() in the InvocableHandlerMethod construction method, and take validationGroups returned by getValidationGroups() method as a member variable. Avoid reflecting to obtain validationGroups every time the call is made

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 20, 2024
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 20, 2024
@jhoeller jhoeller added this to the 6.1.4 milestone Jan 20, 2024
quaff added a commit to quaff/spring-framework that referenced this issue Jan 22, 2024
@quaff
Copy link
Contributor

quaff commented Jan 22, 2024

can call getValidationGroups() in the InvocableHandlerMethod construction method

You can not do that because methodValidator is set after construction, I've fixed this by #32078

quaff added a commit to quaff/spring-framework that referenced this issue Jan 22, 2024
@brucelwl
Copy link
Author

brucelwl commented Jan 22, 2024

can call getValidationGroups() in the InvocableHandlerMethod construction method

You can not do that because methodValidator is set after construction, I've fixed this by #32078

@quaff Sorry, my previous description was incorrect. I would like to correct it. Would it be better to initialize validationGroups in method setMethodValidator(@Nullable MethodValidator methodValidator),

example code:

public void setMethodValidator(@Nullable MethodValidator methodValidator) {
   this.methodValidator = methodValidator;
   this.validationGroups = getValidationGroups();
}

@jhoeller jhoeller self-assigned this Jan 23, 2024
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: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants