JSF Applications (Mojarra 2.2.x) fail to shutdown properly, because Catalina presents a wrapped ServletContext (NoPluggabilityServletContext) in de-init phase (e.g. stop webapp cmd issued via jmx). The problem here is that the wrapped ServletContext (NoPluggabilityServletContext) does not appear to be "equal" (equals, etc. methods not delegated) as the one in the init phase (start). I filed a bug on the mojarra JIRA: https://java.net/jira/browse/JAVASERVERFACES-3687 but it was not accepted, because they argue this is a container issue. Maybe a workaround could fix it for context "comparing" webapps. In this case the mojarra implementation uses a List (CopyOnWriteArrayList) to match (contains) if the ServletContext has been initialized. So a delegation of the "equals" method in the NoPluggabilityServletContext class could do the fix, but might cause other sideeffects in the container, which i didn't lookout. A more detailed approach would be to get a light on the specification - what doues it say about the ServletContext instance and presented proxies in the application lifecycle.
Seeing the same ServletConext for contextInitialized() and contextDestroyed() seems like a reasonable expectation to me. I'd agree that this is something that the Tomcat folks need to take a look at. It is on my list for the coming week.
This has been fixed in trunk, 8.0.x (for 8.0.18 onwards) and 7.0.x (for 7.0.58 onwards).
Just checked the issue with the latest trunk. Seems like it is still not fixed. Now the org.apache.catalina.core.StandardContext$NoPluggabilityServletContext is presented in the init phase. And a org.apache.catalina.core.ApplicationContextFacade in the de-init. How i understand the issue; it is a must to present the same context instance in init and de-init phase?
Check again. This has been fixed and includes a test case to confirm the correct behaviour. Please do not reopen this issue unless you can provide a patch to the existing test case that demonstrates a problem.