You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2002/05/22 17:02:15 UTC

DO NOT REPLY [Bug 9318] New: - HttpSession getMaxInactiveInterval() throws IllegalStateException

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9318>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9318

HttpSession getMaxInactiveInterval() throws IllegalStateException

           Summary: HttpSession getMaxInactiveInterval() throws
                    IllegalStateException
           Product: Tomcat 4
           Version: 4.0.3 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Servlet & JSP API
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: cwilson@andrews.edu


I'm calling session.getMaxInactiveInterval() on a session after it has been 
invalidated.

Tomcat is throwing an IllegalStateException and saying that method cannot be 
called on an invalid session.  However, the Servlet 2.3 API docs do not state 
that IllegalStateException should be thrown (as it is with many other methods 
in HttpSession) from getMaxInactiveInterval().

The reason I've run into this problem is because I'm trying to write a 
HttpSessionAttributeListener that determines if the session is being explicitly 
invalidated or if it timed out.

The Servlet 2.3 spec (section 10.7) states,

"It is often useful in tracking sessions to know whether a session became 
invalid because the container timed out the session, or because a web component 
within the application called the invalidate method. The destinction may be 
determined indirectly using listeners and the HTTPSession API methods."

If I can't call getMaxInactiveInterval() on an invalidated session, how can I 
determine if the session was invalidated due to time out?  Is this a bug in 
Tomcat?  It seems so since it doesn't follow the API docs for this call.

Here is a HttpServletListner the demonstrates the problem:

import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSession;

public class TestListener implements HttpSessionListener {
  
  public void sessionCreated(HttpSessionEvent httpSessionEvent) {
  }
  
  public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
    // ok session should be invalid here...
    // lets test some assertions
    // let put it in a try block to catch any exceptions
    try {
      HttpSession session = httpSessionEvent.getSession();
      
      // lets make sure session is not null
      System.out.println(session == null);
      
      // ok lets try last access time
      // this SHOULD work even if session is invalid
      // javadocs say it will...
      System.out.println(session.getLastAccessedTime());
      // ta-da it does
      
      // ok if that worked then this should work too
      // javadocs do not say it throws IllegalStateException
      System.out.println(session.getMaxInactiveInterval());
      // whoops this breaks...
      // javadocs say this shouldn't happen
      // Servlet spec (10.7) implies using this method to see if
      // a session is invalid because of timeout as opposed
      // to explicit call to session.invalidate();
      
      // now, we won't get here cause the above fails
      // but just to see if the session is invalid
      // lets call something that the javadocs DO say should
      // throw IllegalStateException on an invalid session
      session.invalidate();
    } catch(Exception e) {
      e.printStackTrace();
    }
  }  
}

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>