Hi all,  

I’m trying to write an asynchronous Servlet Filter using Tomcat 7.0.50 as the 
Servlet Container.  

My understanding of the Servlet 3.0 spec regarding the async-supported feature 
is that adding this element to the web.xml for the filter and calling 
ServletRequest#startAsync() should allow the filter to continue its processing 
asynchronously after the doFilter method has returned.  

To test this I created a simple filter which just creates a Future to make a 
call to FilterChain#doFilter. But what I see is a NullPointerException when 
making the call to FilterChain#doFilter.  

From debugging the Tomcat source code, it seems that once my Filters doFilter 
method has returned the StandardWrapperValve#invoke line 283 is calling 
ApplicationFilterChain#release method is being called, which nulls out some 
required variables. So when I make the FilterChain#doFilter call it tries to 
dereference these nulled variables.  

So my question is, if the Servlet API 3.0 spec allows asynchronous Filters then 
why am I seeing a NPE? It seems like a standard use-case. Have I misunderstood 
some part of the spec? Or is this a bug in Tomcat? (And from a quick look seems 
to be the case in 7.0.52 and 8.0.3)  

I have had a quick look at using Jetty 9 and it seems that the call to 
FilterChain#doFilter, in this case, does succeed as expected, i.e. processing 
gets passed to the next filter. (Although I’m seeing issues whilst that filter 
is performing its processing.)  

I’ve created a Gist of the code I used to reproduce the problem if its of any 
help, https://gist.github.com/phillcunnington/9185680.  

Any help with this would be much appreciated as its causing some major 
headaches!  

Thanks  

Phill Cunnington 

Reply via email to