You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by fz...@omnytex.com on 2004/11/08 20:52:14 UTC

Session invalidation problem

Hello all.  I'm cross-posting this to the Tomcat and Struts lists because I'm not sure where is more appropriate to post it.

I have an application that is throwing the following sporadic, but thankfully infrequent, exceptions:

stack trace: java.lang.illegalstateexception: setattribute: session already invalidated

It is on a call to session.setAttribute().  Here's the weird part... Just before that method call I do the following:

if (session == null || session.getAttribute("sessionAlive") == null) {
  request.setAttribute("message", "Your session timed out.  Please log on again.");
  session.invalidate();
  return mapping.findForward("reload");
}

The idea of course is to tell the user their session timed out.  Now, as I understand it, the session==null portion will always be false because session is never null, there is always a session associated with the request, even if it's empty.  That's the reason I put the sessionAlive attribute in during logon and check if THAT is null with each subsequent request to indicate whether the session has timed out or not (please keep the comments about this not being done in the typical way to a minimum... this is an inherited app I'm dealing with).

Any idea why I might still be seeing that exception?  The verbiage of it is a little odd and doesn't seem to make sense, especially considering the check right before that is indicating the session is fine.  I guess it COULD be timing out between that first check and the call to setAttribute(), but I'm assuming the container wouldn't invalidate a session that is attached to a live request, logically that would make sense, so I've more or less discounted this possibility.  I appreciate any thoughts you may have!

Frank W. Zammetti

Re: Session invalidation problem

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Another good point, and I'll add code to catch that.  But, as I 
understand it, session would never be null (not at this point in the 
code anyway, which is inside an Action) because a session would have 
been established by now anyway.

Also, the exception wasn't in this section of code anyway, it actually 
happens about 20 lines after this.  I'm going to take your suggestion 
anyway because I like adding checks that don't hurt anything, might save 
me a headache down the road, but I don't think this will address my 
initial problem.

Thanks Luiz!

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

Luiz Esmiralha wrote:
> On Mon, 8 Nov 2004 11:52:14 -0800 (PST), fzlists@omnytex.com
> <fz...@omnytex.com> wrote:
> 
>>if (session == null || session.getAttribute("sessionAlive") == null) {
>>  request.setAttribute("message", "Your session timed out.  Please log on again.");
>>  session.invalidate();
>>  return mapping.findForward("reload");
>>}
> 
> 
> Calling session.invalidate() will throw a NullPointerException if
> session == null.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Session invalidation problem

Posted by Luiz Esmiralha <es...@gmail.com>.
On Mon, 8 Nov 2004 11:52:14 -0800 (PST), fzlists@omnytex.com
<fz...@omnytex.com> wrote:
> 
> if (session == null || session.getAttribute("sessionAlive") == null) {
>   request.setAttribute("message", "Your session timed out.  Please log on again.");
>   session.invalidate();
>   return mapping.findForward("reload");
> }

Calling session.invalidate() will throw a NullPointerException if
session == null.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org