Clojure/Java: Prevent Exceptions With "trace missing"
Join the DZone community and get the full member experience.
Join For FreeThe other day I got this little helpful exception from Clojure:
(cond (>= nil 1) :unreachable) ;=> NullPointerException [trace missing]
- no line number or anything to troubleshoot it.
It turns out it is not Clojure’s failure but a HotSpot optimization that can apply to NullPointerException
, ArithmeticException
, ArrayIndexOutOfBoundsException
,ArrayStoreException
, and ClassCastException
. The remedy is to run the JVM with
-XX:-OmitStackTraceInFastThrow
From Oralce JDK 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
.
Many thanks to Ivan Kozik for the info!
Published at DZone with permission of Jakub Holý, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments