没有调试代理程序,NullPointerException堆栈跟踪不可用 [英] NullPointerException stack trace not available without debug agent

查看:129
本文介绍了没有调试代理程序,NullPointerException堆栈跟踪不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现了一个导致NullPointerException的错误。使用标准的slf4j语句捕获并记录异常。以下简要代码:

I have recently found a bug that causes a NullPointerException. The exception is caught and logged using a standard slf4j statement. Abridged code below:

for(Action action : actions.getActions()) {
    try {
        context = action.execute(context);
    } catch (Exception e) {
        logger.error("...", e);
        break;
    }
}

正如你所看到的,没什么特别的。但是,在我们拥有的所有异常日志记录语句中,只有这一个不打印堆栈跟踪。它打印的全部是消息(表示为...)和异常类的名称(java.lang.NullPointerException)。

As you can see, nothing fancy. However, of all the exception logging statements that we have, just this one does not print a stack trace. All it prints is the message (represented as "...") and the name of the exception class (java.lang.NullPointerException).

由于堆栈跟踪一个例外是延迟加载,我想可能有一个指令重新排序某种问题,并决定在日志语句之前调用e.getStackTrace()。这没什么区别。

Since the stack trace on an exception is lazy loaded, I thought maybe there is a instruction reordering issue of some sort and decided to call e.getStackTrace() before the log statement. This made no difference.

所以我决定在启用调试代理的情况下重启。但是,因为我甚至附加到过程中,我注意到现在堆栈跟踪正在打印。很明显,调试代理的存在导致一些额外的调试信息变得可用。

So I decided to restart with the debug agent enabled. However, because I even attached to the process, I noticed that now the stack traces were printing. So clearly the presence of the debug agent caused some additional debug information to become available.

此后我修复了异常的根本原因。但我想了解为什么没有调试器就无法使用堆栈跟踪。有人知道吗?

I have since then fixed the root cause of the exception. But I would like to learn why the stack trace was unavailable without a debugger. Anyone know?

澄清:这不是日志记录问题。想象一下相同的try / catch子句,但在catch中,我打印的值为:

Clarification: this is not a logging issue. Imagine the same try/catch clause, but in the catch, I print the value of:

e.getStackTrace().length

如果没有调试器,则打印'0',调试器打印正数(9) case)。

Without a debugger this prints '0', with a debugger it prints a positive number (9 in this case).

更多信息:这发生在JDK 1.6.0_13,64bit,amd64,linux 2.6.9

More info: this is happening on JDK 1.6.0_13, 64bit, amd64, linux 2.6.9

推荐答案

这段代码是否可能在内部循环中?然后,JIT编译器可能正在将此调用堆栈编译为本机代码,从而丢失堆栈信息。然后,当您附加调试器时,它会禁用JIT,使信息再次可用。

Is it possible that this code is in an inner loop? Then then JIT compiler might be compiling the call stack for this to native code, losing the stack information. Then when you attach the debugger it disables the JIT, making the information available again.

其他手动异常会在JIT未优化时继续显示信息。

The other manual exceptions keep displaying the information as the JIT is not optimising.

在第102行的此类源代码中,有时会发生这种情况:

It looks like this can sometimes happen for others from a comment in this class source code at line 102:

http://logging.apache.org/log4j/1.2 /xref/org/apache/log4j/spi/LocationInfo.html

这篇关于没有调试代理程序,NullPointerException堆栈跟踪不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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