Bug 33909 - Context attributes get nullified before ServletContextListener
Summary: Context attributes get nullified before ServletContextListener
Status: RESOLVED DUPLICATE of bug 33463
Alias: None
Product: Tomcat 5
Classification: Unclassified
Component: Servlet & JSP API (show other bugs)
Version: 5.5.7
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-08 18:34 UTC by Archimedes Trajano
Modified: 2005-03-08 09:36 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 ***