We are using Spring Boot 2.1.12 with Spring Web 5.1.3. A controller has a method annotated with @RequestMapping and a mandatory @RequestParam parameter. When the controller is called without the mandatory parameter, Spring Web throws a MissingServletRequestParameterException without a root cause. The ErrorPageFilterin Spring Boot expects all NestedServletExceptions (which MissingServletRequestParameterException is derived from) to have a root cause, leading to the NullPointerException:

java.lang.NullPointerException
    at org.springframework.boot.web.servlet.support.ErrorPageFilter.handleException(ErrorPageFilter.java:165)
    at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:142)
    at org.springframework.boot.web.servlet.support.ErrorPageFilter.access$000(ErrorPageFilter.java:66)
    at org.springframework.boot.web.servlet.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:103)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.springframework.boot.web.servlet.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:121)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    ...

Comment From: wilkinsona

Thanks for the report.

I can see how the NPE could occur in theory but in practice I have been unable to reproduce it. When a MissingServletRequestParameterException is thrown it is caught and handled by DefaultHandlerExceptionResolver which makes a call to sendError and the exception is then swallowed. As a result, the catch block in ErrorPageFilter where the NestedServletException is handled isn't entered.

To allow us to be sure that we fully understand the problem that you're seeing, can you please create a minimal sample that reproduces the problem and share it with us? You can do so by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

Comment From: rmueller83

Generating a sample is not so easy as we are using a large old codebase from the pre-Spring-Boot era. But your hint to DefaultHandlerExceptionResolver was good, as this class is not loaded in our case. Presumably due to the fact that WebMvcAutoConfiguration is disabled. The only implementations of HandlerExceptionResolver that are called in our case are DefaultErrorAttributes and a custom extension of SimpleMappingExceptionResolver.

Comment From: wilkinsona

How are you configuring Spring MVC? If you're not using the auto-configuration, DefaultHandlerExceptionResolver should be configured by org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport which is imported by @EnableWebMvc.

Comment From: rmueller83

We are using a CMS system which provides the Spring configuration within its dependencies. It is xml-based and I do not think that there is a @EnableWebMvc annotation, at least I cannot find one when I zipgrep through the jar files. There are xml bean definitions of RequestMappingHandlerMapping, RequestMappingHandlerAdapter, etc. When I set breakpoints in WebMvcConfigurationSupport, the methods that would instantiate a DefaultHandlerExceptionResolver are not called.

Comment From: wilkinsona

Thanks, @rmueller83. That explains it I think.