| Note | This was reported via spring-projects/spring-framework#22989 and spring-projects/spring-session#1308 | 
It appears that instances of OncePerRequestFilter do not get invoked for error dispatch types on Jetty even when the following conditions are true:
- 
The Filter is configured to dispatch on error dispatch types 
- 
The Filter returns falseforshouldNotFilterErrorDispatch
I created a simple application that demonstrates the issue.
- 
RequestWrapperFilter- 
Is an instance of OncePerRequestFilterwhich returnsfalseforshouldNotFilterErrorDispatch
- 
Wraps the HttpServletRequestwith a dummyRequestWrapper
 
- 
- 
IndexController- 
processes /and/error
- 
sets a model attribute for isWrappedbased on if theHttpServletRequestis wrapped byRequestWrapper
 
- 
You can run on Jetty using the jetty profile (default). On Jetty the sample works for request dispatch (i.e. http://localhost:8080/) and fails for error dispatch (i.e. http://localhost:8080/notfound)
A few observations:
- 
RequestWrapperFilteris invoked the first time and it wraps the request (expected)
- 
RequestWrapperFilteris not invoked on the error dispatch because thehasAlreadyFilteredAttributeistrue(surprising)
- 
RequestWrapperFilterfinally block which clears the attributes is not invoked until after the controller is invoked (surprising)
You can run on Tomcat by ensuring the tomcat profile is active and jetty profile is off. On Tomcat the sample works for both request dispatch (i.e. http://localhost:8080/) and error dispatch (i.e. http://localhost:8080/notfound)
A few observations:
- 
RequestWrapperFilteris invoked the first time and it wraps the request
- 
RequestWrapperFilteris invoked on the error dispatch because thehasAlreadyFilteredAttributeistrue
- 
RequestWrapperFilterfinally block which clears the attributes is invoked before the controller is invoked
To see the failures run the tests with the jetty profile (default). You will observe that the test for a page that is not found fails.
./mvnw test
Rerun the tests using tomcat profile and the tests pass.
./mvnw test -Ptomcat