Skip to content

Validate method parameter index via Java 8 Method.getParameterCount() [SPR-13456] #18036

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

Closed
spring-projects-issues opened this issue Sep 10, 2015 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Sep 10, 2015

俞火江 opened SPR-13456 and commented

If the value for parameterIndex is too great when constructing a MethodParameter, an ArrayIndexOutOfBoundsException will be thrown later when some method such as getParameterType() is called. So why not detect the error as early as possible?


Affects: 4.2.1

Issue Links:

Referenced from: commits 39e3f2e

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

The main reason why we are not checking a parameter index early is the inefficiency of Method.getParameterTypes() which copies the Class array every time: If we are just calling this for determining the parameter count, it's quite a waste. However, as of Java 8, there is Method.getParameterCount() as a much more efficient variant for that purpose. We'll use this across the codebase as of Spring Framework 5.0.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

俞火江 commented

Quite reasonable

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 6, 2016

Juergen Hoeller commented

Fixed along with #18627.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants