tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Barkan <dbar...@pcbi.upenn.edu>
Subject RE: NullPointerException during HttpServletRequest.getSession
Date Tue, 30 Sep 2003 20:04:49 GMT
OK thanks for responding to my first question; I looked around, some 
interesting discoveries within:

On Tue, 30 Sep 2003, Shapira, Yoav wrote:
> 
> Howdy,
> 
> >The symptom is a NullPointerException when I call getSession() on an
> >HttpServletRequest object.  The HttpServletRequest object had
> previously
> >been saved as an attribute of the Session that it contained.
> 
> This seems prone to problems.  How can storing the request itself as a
> session attribute be valid?  A session by definition may have many
> requests in it -- so you override the value of the attribute when a new
> request comes in?

This is true; although everything had worked previously until we upgraded 
to the new tomcat specifications.  However the same behavior occurs when I 
hacked by saving the HttpServletRequest in a global variable for later 
use.  Also, see below:

> 
> >I tried looking at the CoyoteRequestFacade code but the directory
> >containing it in the public download site was empty!  That was the code
> >that threw the actual exception so I'm sure it could give some insight.
> 
> It's here:
> http://cvs.apache.org/viewcvs/jakarta-tomcat-connectors/coyote/src/java/
> org/apache/coyote/tomcat4/CoyoteRequestFacade.java?rev=1.3&content-type=
> text/vnd.viewcvs-markup
> 
> However, it's been modified since the last release so the line number
> may not be accurate.  Anyways, it's likely the request object itself had
> been nulled out, giving NPE in request.getSession(....).
> 
Yes I think so as well, that looks like the only thing that can throw the 
NPE.  I'm wondering where the nullification could have taken place, since 
the CoyoteRequestFacade is still intact, I will look around.  However, I 
noticed this wile looking at the CoyoteRequestFacade code:

CoyoteRequestFacade.java:

public HttpSession getSession(boolean create) {
        return request.getSession(create);
}

CoyoteRequest.java:
/**
 * Return the session associated with this Request, creating one
 * if necessary and requested.
 *
 * @param create Create a new session if one does not exist
 */
 public HttpSession getSession(boolean create) {
      return null;
 }

This was in the cvs repository; if this is an accurate reflection of the 
library I'm using then it seems I am always getting a null Session.  
However I think the CoyoteRequest being null is actually throwing the 
error, rather than the session, so either something is nullifying the 
CoyoteRequest, or that cvs code is not the code I'm using, or both.

Thanks for your help!
Dave Barkan



Mime
View raw message