Skip to content

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

Closed
@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions