Getting Readable Tracebacks
Problem
You’re getting an exception stack trace at runtime, but most of the important parts don’t have line numbers.
Solution
Disable JIT and run it again. Or use the current HotSpot runtime.
Discussion
When a Java program throws an exception, the exception propagates up
the call stack until there is a
catch
clause that matches it. If none is
found, the Java interpreter program catches it and prints a stack
traceback showing all the method calls that got from the top of the
program to the place where the exception was thrown. You can print
this traceback yourself in any catch clause: the
Throwable
class has several methods called
printStackTrace( ).
The Just-In-Time (JIT) translation process consists of having the Java runtime convert part of your compiled class file into machine language, so that it can run at full execution speed. This is a necessary step for making Java programs run under interpretation and still be acceptably fast. However, until recently its one drawback was that it generally lost the line numbers. Hence, when your program died, you still got a stack traceback but it no longer showed the line numbers where the error occurred. So we have the tradeoff of making the program run faster, but harder to debug. The latest versions of Sun’s Java runtime include the HotSpot Just-In-Time translator, which doesn’t have this problem.
If you’re still using an older (or non-Sun) JIT, there is a way around this. If the program is getting a stack ...