The NullPointerException in Java seems to only report that it occurred on a particular line of code. Is it possible to alter that exception to state which variable was null if there is more than one variable used in a line of code?
The NullPointerException in Java seems to only report that it occurred on a particular
Share
No, the debug information in the class file does not contain enough information to allow this.
You can, however, improve on the situation. There are two things that can cause a NPE to be thrown:
.dereferencing a variable, likefoo.bar().[indexing an array, likeargs[0].If you write your code so there is only one of these on a given code line, there is simply no doubt about which one caused the NPE. It will introduce a lot of temporary variables but then you have more information readily available when debugging.