LoginSignup
23

More than 5 years have passed since last update.

例外のスタックトレースが出力されない・・・?

Last updated at Posted at 2012-05-23

【事象】
以下のようなとき、例外のスタックトレースがまったく出力されないことがある。

try{

    // ・・・

} catch(NullPointerException e) {
    log.error("error!", e);
}

e.getStackTrace().lengthで、
例外のスタックトレースサイズを見ると、0になっている。

【原因】
JVMは、同じような箇所で組み込み例外が繰り返しthrowされると、
メソッドを再コンパイルして最適化することがある。

この最適化されたメソッドでは、
JVMが事前に用意した例外インスタンスがthrowされ、
その例外インスタンスにはスタックトレースが提供されない。
これが原因。

-XX:-OmitStackTraceInFastThrowオプションでJVMを起動することで、
この最適化を無効にすることができる。

http://java.sun.com/j2se/1.5.0/ja/relnotes.html
(HotSpot VM 参照)

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23