English 中文(简体)
为什么空指针异常对象有一个空的原因字段?
原标题:Why do Null Pointer Exception objects have an empty cause field?

我正在监控一些服务器日志,有相当多的NullPointerExceptions。日志包含堆栈跟踪和来自getCause原因

问题在于这些NPE(NullPointerException)不包含原因。在JavaDocs中,它表示当原因不存在或未知时为空(不是很有用)。

那么我的问题是,有人遇到过这些“无明显原因”的 NPE 吗?如果有,那么在那种情况下是什么问题呢?我有点迷失在这里,所以任何见解都将不胜感激。

最佳回答

NPEs从来没有原因,因为它们是由JVM在尝试访问空对象引用时生成的。堆栈跟踪应该有关于它发生的代码行的信息。

问题回答

NullPointerException的原因通常可以从堆栈跟踪中清晰地看出。您查看发生错误的行并观察那里可能为空。这里没有进一步的原因(原因在这里是由NullPointerException包装的不同异常)。

如果NullPointerException没有堆栈跟踪,那可能会发生,并且是更难诊断的问题,但如果我理解你的问题,那这里不是这种情况。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签