Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recurring Exception without a stack trace - how to reset? [duplicate]

Tags:

java

exception

In my application log (using log4j), I see a NullPointerException, but without the stack trace. I know that as an optimization, when an exception occurs many times - the jvm stops producing the stack trace. The problem is the exception occurred some time ago, and all my logs are filled with the exception without the stack trace. Is there a way to "reset" this mechanism, so the next thrown exception will be printed with the full stack trace? I don't want to restart the application, as it is hard to reproduce this bug, and restarting may cause to "go away"...

Thanks!

like image 632
duduamar Avatar asked Jan 11 '11 15:01

duduamar


People also ask

How do I stop stack trace?

If you want to disable it for all exceptions, you can use a byte code instrumentation agent to replace the fillInStackTrace method in the Throwable class. That will however only work for Java 6, since you in Java 5 are not allowed to replace a native method (fillInStackTrace) with a Java method using instrumentation.

What causes stack trace error?

Common Problems With Stack Traces and Third-Party Packages In some cases, an error occurs when you send incorrect input to one of the third-party libraries you use. As you might expect, your program will print a stack trace of the function calls leading up to the problem.

Why is exception PrintStackTrace () considered bad practice?

It is not bad practice because something is 'wrong' about PrintStackTrace(), but because it's 'code smell'. Most of the time the PrintStackTrace() call is there because somebody failed to properly handle the exception.

Can exception stack trace null?

Yes. If you create a new Exception() and don't throw it, every property except Data and Message will be null.


1 Answers

Try running with the following JVM property:

-XX:-OmitStackTraceInFastThrow 

From the Release Notes:

The compiler in the server VM now provides correct stack backtraces for all "cold" built-in exceptions. For performance purposes, when such an exception is thrown a few times, the method may be recompiled. After recompilation, the compiler may choose a faster tactic using preallocated exceptions that do not provide a stack trace. To disable completely the use of preallocated exceptions, use this new flag: -XX:-OmitStackTraceInFastThrow.

like image 155
dogbane Avatar answered Sep 25 '22 13:09

dogbane