Bug 33909

Summary: Context attributes get nullified before ServletContextListener
Product: Tomcat 5 Reporter: Archimedes Trajano <trajano>
Component: Servlet & JSP APIAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 5.5.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   

Description Archimedes Trajano 2005-03-08 18:34:11 UTC
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.
Comment 1 Remy Maucherat 2005-03-08 18:36:23 UTC

*** This bug has been marked as a duplicate of 33463 ***