Skip to content

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

Closed

Description

@spring-projects-issues

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

Activity

  1. added
    type: bug
    in: web
    on Jan 11, 2019
  2. added this to the 5.1.4 milestone on Jan 11, 2019
  3. shollander commented on Jan 16, 2019

    @shollander

    @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.

  4. rstoyanchev commented on Jan 17, 2019

    @rstoyanchev
    Contributor

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

  5. shollander commented on Jan 18, 2019

    @shollander

    @rstoyanchev Thank you.

  6. modified the milestones: 5.1.4, 5.1.5 on Jan 21, 2019
  7. jhoeller commented on Jan 24, 2019

    @jhoeller
    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.

  8. modified the milestones: 5.1.5, 5.1.4 on Jan 24, 2019
  9. Moonergfp commented on Jun 28, 2023

    @Moonergfp
  10. bclozel commented on Jun 28, 2023

    @bclozel
    Member
  11. bclozel commented on Jun 28, 2023

    @bclozel
    Member

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

  12. Moonergfp commented on Jun 28, 2023

    @Moonergfp

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

  13. bclozel commented on Jun 28, 2023

    @bclozel
    Member

    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

Metadata

Metadata

Assignees

Labels

in: webtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions