-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regressionA bug that is also a regression
Milestone
Description
The parameter names from the handler method that is passed to the preHandle method of a HandlerInterceptor are null when the endpoint is called for the first time after the application has been started.
Steps to reproduce:
- Create a project with the Spring Initializr using Spring Boot version 4.0.0 and the Spring Web Dependency.
- Add the following code in the DemoApplication
package com.example.demo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@RestController
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("test")
public void test(@RequestParam String test) {
}
@Bean
WebMvcConfigurer webMvcConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TestHandlerInterceptor());
}
};
}
static class TestHandlerInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) {
if (handler instanceof HandlerMethod handlerMethod) {
System.out.println(handlerMethod);
for (var methodParameter : handlerMethod.getMethodParameters()) {
System.out.println("Parameter Index: " + methodParameter.getParameterIndex());
System.out.println("Parameter Type: " + methodParameter.getParameterType());
System.out.println("Parameter Name: " + methodParameter.getParameterName());
}
}
return true;
}
}
}- Start the application
- Call the endpoint:
curl localhost:8080/test?test=test - The console output shows null for the parameter name
com.example.demo.DemoApplication#test(String)
Parameter Index: 0
Parameter Type: class java.lang.String
Parameter Name: null
- Call the endpoint again the same way.
- Now the console output has the parameter name set as expected.
com.example.demo.DemoApplication#test(String)
Parameter Index: 0
Parameter Type: class java.lang.String
Parameter Name: test
As far as i can tell the parameter names are only null during the first call per endpoint in the application and the problem also seems to be isolated to the preHandle method in the Interceptor. The values are correct in the postHandle even during the first call for a endpoint.
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regressionA bug that is also a regression