wood burning stoves*
The moose likes Servlets and the fly likes NullPointerException on request.getSession() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "NullPointerException on request.getSession()" Watch "NullPointerException on request.getSession()" New topic
Author

NullPointerException on request.getSession()

Jason Rubrick
Greenhorn

Joined: Aug 13, 2009
Posts: 5
I'm getting an NPE on a if (request.getSession(false) == null) intermittantly. Sometimes it returns fine, especially initally, but usually if I wait about 30 secs, it throws the exception. I'm not sure why this would ever throw an NPE. A scope issue?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

Moved to the Servlets forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

We'll need more context.

You're not doing anything like hanging onto the request reference after the request has finished, are you?
Jason Rubrick
Greenhorn

Joined: Aug 13, 2009
Posts: 5
Not sure about hanging onto the reference on the request.getSession(false). There's a session variable that's used to look up other information after the session is retrieved. It's done in a bean used on a number of jsp pages. But the same pages will sometimes return the NPE on the request.getSession and sometimes not.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

How is the request reference getting to the bean?

Again, more context please. If you are going to skimp on details, the amount of help you can receive is limited.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

NPE - if (request.getSession(false) == null)


Impossible. This suggests that the request object is null, which does not make sense. Are you sure this is the line that causes the NPE ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Jason Rubrick
Greenhorn

Joined: Aug 13, 2009
Posts: 5
Yes, that's what I don't understand. I didn't think it was possible for that to return an NPE. Here's the code of the method where the exception occurs. I put an extra try /catch in to isolate where it happens. The actual exception occured just afterwards on the boolean showAuthId = ProfileBean.showAuthId(request.getSession());


Jason Rubrick
Greenhorn

Joined: Aug 13, 2009
Posts: 5
Another thing -- this just started happening on a weblogic upgrade, going from 6 --> 10.3.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
can you post the stack trace?


“Everything should be as simple as it is, but not simpler.” Albert Einstein
Jason Rubrick
Greenhorn

Joined: Aug 13, 2009
Posts: 5
Sure -- heres the stacktrace:

java.lang.NullPointerException
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.initSessio
nInfo(ServletRequestImpl.java:2509)
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.getSession
Internal(ServletRequestImpl.java:2281)
at weblogic.servlet.internal.ServletRequestImpl$SessionHelper.getSession
(ServletRequestImpl.java:2271)
at weblogic.servlet.internal.ServletRequestImpl.getSession(ServletReques
tImpl.java:1245)
at ngts.imaster.beans.BatchBean.buildFormattedList(BatchBean.java:1041)
at ngts.imaster.beans.BatchBean.getFormattedList(BatchBean.java:982)
at ngts.imaster.beans.ListTemplateBean.getFormattedList(ListTemplateBean
.java:68)
at jsp_servlet._backoffice._en.__list_template._jspService(__list_templa
te.java:183)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run
(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecuri
tyHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:175)
at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(Request
DispatcherImpl.java:505)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispat
cherImpl.java:251)
at ngts.imaster.generic.servlet.PostGetServlet.handleClientRequestReal(P
ostGetServlet.java:253)
at ngts.imaster.generic.servlet.PostGetServlet.handleClientRequest(PostG
etServlet.java:107)
at ngts.imaster.generic.servlet.GenericECIServlet.processEvent(GenericEC
IServlet.java:110)
at ngts.imaster.generic.servlet.GenericECIServlet.doGet(GenericECIServle
t.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run
(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecuri
tyHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.jav
a:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:3498)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
dSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppS
ervletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletC
ontext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.j
ava:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60792
    
  65

As the NPE is happening deep within the container code, I still suspect that you are hanging onto a request reference long after you should.

When is this code executing in relation to the life cycle of the request?
Duc Vo
Ranch Hand

Joined: Nov 20, 2008
Posts: 254
Since the problem is because of upgrading, can you check if you include any server libraries in the deployment package?
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
hi,
At one place you are retrieving session using "GenericWebObject" , why dont you try by the similar way when you need it again?
Also in the method I was not able to find "request" variable. Are you relying on any instance variable for initialization of this "request" variable.

Regards,
Amit
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException on request.getSession()
 
Similar Threads
Confused about getSession
Hibernate--->Sqlserver
issue with a static method definition
accessing a .properties file
problem with SQL query....