Delphi Clinic | C++Builder Gate | Training & Consultancy | Delphi Notes Weblog | Dr.Bob's Webshop |
|
No line numbers with a NullPointerException
When running programs we sometimes encounter NullPointerExceptions.
And when the application comes accross a NullPointerException, the application will print an error stack trace.
In this stack trace we can find the line number where the exception occurred.
Right? Well, not quite...
Take for example this simple application:
public class MyClass1 { public static void main(String[] args) { String.valueOf(null); } }When we run this application we get the following output (the statement in line 3 throws the exception):
java.lang.NullPointerException at java.lang.String.We notice not all line numbers are shown. In this case we maybe don't mind, but sometimes we do. In order to see those line numbers also, we must disable the JIT compiler. The JIT compiler makes we cannot see the line numbers always.(Compiled Code) at java.lang.String.valueOf(String.java:1372) at com.drbob42.jbjar.tip28.MyClass1.main(MyClass1.java:5)
To disable the JIT compiler we go to the Project properties, and select the Run / Debug tab page. On this page we can assign JVM parameters. This parameters will be used by the JVM. Now we fill in -nojit in this field to disable the JIT compiler.
When we run the application again we see all the line numbers:
java.lang.NullPointerException at java.lang.String.<init>(String.java:132) at java.lang.String.valueOf(String.java:1372) at com.drbob42.jbjar.tip28.MyClass1.main(MyClass1.java:5)