HandlerMethodValidationException.Visitor
incorrectly triggers other()
method instead of requestParam()
for @RequestParam
validation errors
#31329
Milestone
Environment
Spring Boot: 3.2.0-M3
Spring Web: spring-web-6.1.0-M5.jar
Java: 17
Expected Behavior:
When a
@RequestParam
value is invalid,HandlerMethodValidationException.Visitor
should call therequestParam(RequestParam, ParameterValidationResult)
method.Observed Behavior:
Instead,
HandlerMethodValidationException.Visitor
callsother(ParameterValidationResult)
.Reproduce the error
Spring Initializr
Execute
curl --location 'localhost:8080/api/invalid?num=-5'
Debugging Insights
In
HandlerMethodValidationException#visitResults(HandlerMethodValidationException.Visitor)
:Line
this.requestParamPredicate.test(param)
is false, because:↓
In
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#methodParamPredicate(List, Class)}
Line
return resolverType.isInstance(resolver);
returns false, because:↓
resolverType
isclass org.springframework.web.service.invoker.RequestParamArgumentResolver
andresolver.getClass()
isclass org.springframework.web.method.annotation.RequestParamMethodArgumentResolver
The mismatch between
resolverType
andresolver.getClass()
appears to be the crux of the problem.Thank you for looking into this!
The text was updated successfully, but these errors were encountered: