Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Inconsistency with Listeners  RSS feed

 
Trish Wu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For ServletContextListener's contextDestroyed(),
it is ok to get the attribute within this method through the event obj.
Whereas in HttpSessionListener's sessionDestroyed(). it will throw an IllegalStateException when trying to obtain the attribute from a session.
So does anyone know the rationale behind this inconsistency?
 
Bill Wang
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the spec, sessionDestroyed(HttpSessionEvent se)Notification that a session was invalidated. This happens after session invalidation. When you tried to get a session attribute ref, you will get IllegalStateException.
While in ServletContextListener, contextDestroyed(ServletContextEvent sce)Notification that the servlet context is about to be shut down. This happens before the invalidation, so reference to any context attributes is still valid.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!