Skip to content

NullPointerException in ErrorPageFilter when a MissingServletRequestParameterException is thrown and there's no DefaultHandlerExceptionResolver #22169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmueller83 opened this issue Jun 30, 2020 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@rmueller83
Copy link

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)
	...
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 30, 2020
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jun 30, 2020
@rmueller83
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 30, 2020
@wilkinsona
Copy link
Member

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.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jun 30, 2020
@rmueller83
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jul 2, 2020
@wilkinsona
Copy link
Member

Thanks, @rmueller83. That explains it I think.

@wilkinsona wilkinsona changed the title NullPointerException in ErrorPageFilter NullPointerException in ErrorPageFilter when a MissingServletRequestParameterException is thrown and there's no DefaultHandlerExceptionResolver Jul 6, 2020
@wilkinsona wilkinsona added type: bug A general bug for: team-attention An issue we'd like other members of the team to review and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jul 6, 2020
@philwebb philwebb added this to the 2.1.16 milestone Jul 6, 2020
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Jul 6, 2020
@wilkinsona wilkinsona self-assigned this Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants