-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement
Milestone
Description
MockMvc supports calling init(FilterConfig)
on filters added to it with URL mappings and/or init params and dispatcher types. This was done in 6.1 with #31362.
A filter that's being initialized may in turn try to access the FilterRegistration
. Currently that's not initialized, and that can cause problems. For example:
Caused by: java.lang.NullPointerException: Cannot invoke "jakarta.servlet.FilterRegistration.getUrlPatternMappings()" because "filterRegistration" is null
at org.glassfish.jersey.servlet.init.FilterUrlMappingsProviderImpl.getFilterUrlMappings(FilterUrlMappingsProviderImpl.java:43)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:414)
at org.springframework.test.web.servlet.setup.MockMvcFilterDecorator.initIfRequired(MockMvcFilterDecorator.java:201)
at org.springframework.test.web.servlet.setup.AbstractMockMvcBuilder.build(AbstractMockMvcBuilder.java:191)
at org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration.mockMvc(MockMvcAutoConfiguration.java:97)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:146)
... 125 more
We can update MockServletContext
to support adding FilterRegistration
s, and then make sure that's added in MockMvc along with the FilterConfig
it prepares.
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancementA general enhancement