Java中没有StackTrace的NullPointerException [英] NullPointerException in Java with no StackTrace

查看:129
本文介绍了Java中没有StackTrace的NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Java代码的实例捕获 NullPointerException ,但是当我尝试记录StackTrace时(基本上最终调用 Throwable .printStackTrace()),我得到的是:

  java.lang.NullPointerException 

有没有其他人遇到这个?我试着谷歌搜索java空指针空堆栈跟踪但没有遇到这样的事情。

解决方案

你可能使用Sun JVM,它执行大量优化。要获得堆栈跟踪,您需要将选项 -XX:-OmitStackTraceInFastThrow 传递给JVM。



现代OpenJDK JVM(1.8及更高版本?)似乎也接受 -XX:-OmitStackTraceInFastThrow 标志(默认情况下也启用了堆栈跟踪优化)。 / p>

I've had instances of our Java code catch a NullPointerException, but when I try to log the StackTrace (which basically ends up calling Throwable.printStackTrace() ), all I get is:

java.lang.NullPointerException

Has anyone else come across this? I tried googling for "java null pointer empty stack trace" but didn't come across anything like this.

解决方案

You are probably using the Sun JVM, which performs a lot of optimization. To get the stack traces back, you need to pass the option -XX:-OmitStackTraceInFastThrow to the JVM.

Modern OpenJDK JVMs (1.8 and higher?) seem to accept the -XX:-OmitStackTraceInFastThrow flag as well (and have stack-trace optimization turned on by default) as well.

这篇关于Java中没有StackTrace的NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆