It seems that context attributes get nullified before ServletContextListener I have created a small ServletContextListener and this causes a NullPointerException on contextDestroyed. public class ProblemListener implements ServletContextListener { public void contextInitialized(ServletContextEvent arg0) { SimpleClass contextObject = new SimpleClass(); arg0.getServletContext().setAttribute("CONTEXT", contextObject); } public void contextDestroyed(ServletContextEvent arg0) { SimpleClass container = (SimpleClass) arg0.getServletContext ().getAttribute("CONTEXT"); container.setFoo("ABC!!!!"); arg0.getServletContext().removeAttribute("CONTEXT"); } } SimpleClass is a bean that as a getter and setter called Foo and a finalizer that does System.out.println("FINALIZE THIS"); The sample from Sun (near the bottom of http://java.sun.com/j2ee/tutorial/1_3- fcs/doc/Servlets4.html) sounds like it should not be null at that point.
*** This bug has been marked as a duplicate of 33463 ***