views:

164

answers:

3

Hi guys,

I'm monitoring some server logs and there are quite a few NullPointerExceptions. The logs contain the stacktrace and the cause from getCause.

The problem is that these NPEs do not contain a cause. In the JavaDocs it says that the cause is null when it's inexistent or unknown (not very helpful).

So my question is, has somebody run into these "causeless" NPEs? If so, which was the problem in that situation? I'm kinda lost here so any insight will be appreciated.

+1  A: 

Post a stacktrace.

Voytek Jarnot
+3  A: 

NPEs never have causes because their generated by the JVM when you try to access a null object reference. The stacktrace should have information about the line where it happened.

helios
Thanks, I was probably confused with other kinds of exceptions. The information I'm seeing in the stacktrace is lacking though but it's not because of the cause (as you said).
Pablo Fernandez
Never say never. It is possible (though of course a horrible idea) to manually create a NPE, initCause, then throw it.
Matthew Flaschen
@Matt I'm for sure not doing that :)
Pablo Fernandez
@Matthew He he, good point. I could add 'in a normal scenario'. :)
helios
+3  A: 

The cause of a NullPointerException is generally very clear from the stacktrace. You look at the line where it happened and observe what can be null there. There is no further cause (cause here being a different exception that was wrapped by the NullPointerException).

If the NullPointerException has no stacktrace, that can happen and is a harder problem to diagnose, but if I understand your question that is not the case here.

Yishai