• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException... what is left to check?

 
Dan Acuff
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a NullPointerException on the "detail page" of our application.
So I assume it is something in the detail page section of my class that is throwing the NullPointerException.

But I am checking what looks to be all I can check for a null value. This is just the piece that sets values if on a detail page.



Is there something I am missing?

Because I am using an include to call this class I only get an error on the include page for example:

javax.faces.FacesException: javax.el.ELException: /store/shop/layout/template.xhtml @62,52 value="#{coreMetrics.buildCoreMetricsString()}": java.lang.NullPointerException
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that piece of code I see four possibilities:
- cm_ScriptName is null
- customerSession is null
- customerSession.getSelectedItem() returns null
- cm_output_common is null
 
Dan Acuff
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I originally set some of the variables to ""; is that a fair approach?

For example near the top of the class I set:



So I feel that eliminates 2 possibilities.

Could you show me how to test for customerSession and customerSession.getSelectedItem() having a null value?
 
Dan Acuff
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Gang.

I came up with this to do checks on the objects.



I hope it works, we are going to deploy and hopefully not see the dreaded NullPointerException anymore.
 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you doing all those != null checks, rather than displaying them on screen. You need to find where the nulls are coming from.Alternative:Note the %b tag will take foo != null, or foo alone as an argument, displaying "false" from any null reference or false boolean/Boolean and "true" from anything else, including primitives, as far as I can remember.
 
Dan Acuff
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. If my return type for the class is a String.

Will the below be forced on to my web page? I tried it like shown but nothing appeared on my web page.

 
Campbell Ritchie
Sheriff
Posts: 48386
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would expect that printout at your command line or terminal.
 
Paul Clapham
Sheriff
Pie
Posts: 20742
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Acuff wrote:Hi. If my return type for the class is a String.

Will the below be forced on to my web page? I tried it like shown but nothing appeared on my web page.



If the code is in a web application, then no. It will probably go to one of the application server's log files, but exactly which one is server-dependent.

Of course if your question is how to make debugging output appear on the web page, well, you do know how to make text appear on the web page, don't you? Just do that.
 
Dan Acuff
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clearing the up! I was starting to get a bit confused.

Yes I can return values to the web-app screen.

The biggest problem I am having is actually reproducing the error. It's like it happens 1 time on a deployment and then it never happens again.

So I am thinking maybe the customerSession was blank or something similar.. but even that does not make sense since you have to be signed in (thereby having a customerSession) before being able to see the detail page where the last 3 reports of it occuring have happened.

It get's tricky when it happens as rarely as it is since I don't know how to reproduce the conditions.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic