Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

NullPointerException on request.getSession()

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the Servlets forum.
 
Bear Bibeault
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ?
 
Jason Rubrick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing -- this just started happening on a weblogic upgrade, going from 6 --> 10.3.
 
Bear Bibeault
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you post the stack trace?
 
Jason Rubrick
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67619
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since the problem is because of upgrading, can you check if you include any server libraries in the deployment package?
 
Ranch Hand
Posts: 544
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic