Skip to content

MethodParameter.isOptional() fails with ArrayIndexOutOfBoundsException [SPR-17629] #22160

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 Dec 28, 2018 · 10 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 28, 2018

shollander opened SPR-17629 and commented

Calling org.springframework.core.MethodParameter.isOptional() can fail with an ArrayIndexOutOfBoundsException. I have a custom ResponseBodyAdvice class that calls this method in supports(). It fails when it hits org.springframework.boot.actuate.endpoint.web.servelt.WebMvcEndpointHandlerMappings$WebMvcLinksHandler.links with the following exception:

java.lang.ArrayIndexOutOfBoundsException: -1
    at org.springframework.web.method.HandlerMethod$HandlerMethodParamater.getParameterAnnotations(HandlerMethod.java:484) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.core.MethodParameter.hasNullableAnnotation(MethodParameter.java:357) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.core.MethodParameter.isOptional(MethodParameter.java:345) ~[spring-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at com.example.advice.OptionalResponseBodyAdvice.supports(OptionalResponseBodyAdvice.java:18) ~[main/:na]
    at org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceChain.processBody(RequestBodyAdviceChain.java:140) ~[spring-webmvc-5.1.3.RELEASE.jar:5.1.3.RELEASE]

Affects: 5.1.3

Issue Links:

Referenced from: commits 1faeeae

@shollander
Copy link

shollander commented Jan 16, 2019

@jhoeller This issue has not been fixed in 5.1.4. I still get the same ArrayIndexOutOfBoundsException, this time at line 486:

java.lang.ArrayIndexOutOfBoundsException: -1
    at org.springframework.web.method.HandlerMethod$HandlerMethodParamater.getParameterAnnotations(HandlerMethod.java:486) ~[spring-web-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.core.MethodParameter.hasNullableAnnotation(MethodParameter.java:357) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at org.springframework.core.MethodParameter.isOptional(MethodParameter.java:345) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
    at com.example.advice.OptionalResponseBodyAdvice.supports(OptionalResponseBodyAdvice.java:19) ~[main/:na]
    at org.springframework.web.servlet.mvc.method.annotation.RequestBodyAdviceChain.processBody(RequestBodyAdviceChain.java:140) ~[spring-webmvc-5.1.4.RELEASE.jar:5.1.4.RELEASE]

The problem is that the getParameterIndex() method called at

will return -1 (as documented in its JavaDoc) in the case of a return type. The change in 1faeeae only addresses checking the upper bounds of index but not the lower bounds.

@rstoyanchev
Copy link
Contributor

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

@shollander
Copy link

@rstoyanchev Thank you.

@jhoeller
Copy link
Contributor

I've created #22303 as a follow-up for 5.1.5, leaving this one as the ticket for the 5.1.4 release.

@jhoeller jhoeller modified the milestones: 5.1.5, 5.1.4 Jan 24, 2019
@Moonergfp
Copy link

The 5.1.5 release notes don't contain the update, do they? i don't find it out.
https://github.com/spring-projects/spring-framework/releases?page=9

@bclozel
Copy link
Member

bclozel commented Jun 28, 2023

@Moonergfp I'm seeing it listed under the bugs section on the release page: https://github.com/spring-projects/spring-framework/releases/tag/v5.1.5.RELEASE

@Moonergfp
Copy link

I see, but what is the difference between these two release notes? And why does the description in https://github.com/spring-projects/spring-framework/releases?page=9 have fewer details than https://github.com/spring-projects/spring-framework/releases/tag/v5.1.5.RELEASE?
@bclozel

@bclozel
Copy link
Member

bclozel commented Jun 28, 2023

@Moonergfp The first link is a link to a page, a collection of releases. The second link is a link to a single release.

@Moonergfp
Copy link

@bclozel But the description content in the first link, regarding v5.1.5.RELEASE, is less detailed than the second

@bclozel
Copy link
Member

bclozel commented Jun 28, 2023

I don't see a v5.1.5.RELEASE release on that page.

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: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants