开发者

Why do Null Pointer Exception objects have an empty cause field?

开发者 https://www.devze.com 2022-12-20 06:16 出处:网络
I\'m monitoring some server logs and there are quite a few NullPointerExceptions. The logs contain the stacktrace and the cause from getCause.

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 开发者_C百科so, which was the problem in that situation? I'm kinda lost here so any insight will be appreciated.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号