• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Getting a NullPointerException Even If I Check for Null

 
Ranch Hand
Posts: 2003
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a NullPointerException on line 14(LogOn logOn = (LogOn)session.getAttribute("logonObj");):

 
Marshal
Posts: 15630
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strange, but try this instead:
 
Saloon Keeper
Posts: 7175
65
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Seems that line 14 can't be the problem and that it must be the line before or after. Are you sure the line numbers that show up in your post match those in your editor? It would also help if you cut and paste the entire error message into a post. Error message sometimes have other hints.
 
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Carey.  If your stack trace really points to " LogOn logOn = (LogOn)session.getAttribute("logonObj");" that seems impossible.  It suggests that the code being executed is not the same as the source you're looking at.  Perhaps there's an older .class or jar file somewhere?
 
Mike Simmons
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To elaborate, that line should only NullPointer if the session were null.  If that were the case, then line 12 should error first, from the session.getAttribute("logonObj").  It may be necessary to add an "if (session != null)" first...
 
Sheriff
Posts: 21949
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 9 would error first: session.getServletContext().
 
Mike Simmons
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's right, oops.
 
Steve Dyke
Ranch Hand
Posts: 2003
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Seems that line 14 can't be the problem and that it must be the line before or after. Are you sure the line numbers that show up in your post match those in your editor? It would also help if you cut and paste the entire error message into a post. Error message sometimes have other hints.





[6/8/20 7:13:57:293 CDT] 00000144 SystemErr     R java.lang.NullPointerException
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.FAIWebApp._qualitycontrol.firstarticle.current.misc.RemoveFAILock.<init>(RemoveFAILock.java:35)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.FAIWebApp._initialize.logonconnections.misc.FileCleanUp.<init>(FileCleanUp.java:32)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.FAIWebApp._initialize.controllers.LogonControllerServlet.doPost(LogonControllerServlet.java:337)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1232)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:781)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:480)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:136)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:97)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.FAIWebApp._application.qms.QMSFilterImproved.doFilter(QMSFilterImproved.java:138)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:195)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:91)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:967)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1107)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:87)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:947)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1817)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:558)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:608)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:985)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1074)
[6/8/20 7:13:57:352 CDT] 00000144 SystemErr     R at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1892)
 
Mike Simmons
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so in your local copy, what is on RemoveFAILock.java line 35?  Is it

or something else?
 
Steve Dyke
Ranch Hand
Posts: 2003
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:OK, so in your local copy, what is on RemoveFAILock.java line 35?  Is it

or something else?



It is the line of code you mentioned.
 
Mike Simmons
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so that's different from the original error. If that line is throwing NPE, it would be because logOn is null, or logOn.getUserObject() is null, or logOn.getUserObject().getFullnameMod() is null.  You may need to check for all of those.
 
Rob Spoor
Sheriff
Posts: 21949
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At times like this I miss a proper null-safe operator like C# and several other languages have...
is so much shorter than the Java alternative.
 
Mike Simmons
Master Rancher
Posts: 3537
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed.  Insert Kotlin plug here.
 
Saloon Keeper
Posts: 12008
257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not as pretty, but you could do something similar to the null-propagating operator by using Optional:

I'm more concerned that Steve is still not using data sources properly, and that his queries might be susceptible to injection attacks, depending on how the session is maintained.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic