Useful message about NullPointerException

pike pike630 at hotmail.com
Tue Jan 27 14:45:31 UTC 2015


kedar mhaswade wrote
> When the JVM executes instructions like getfield
> <http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.getfield>,
> getstatic, invokevirtual etc. with *objref* on the operand stack and if
> *objref* is null, an NPE is thrown. It appears that the JVM could tell us
> more about which *objref* was null at run-time. Candidate for an RFE?

Yes, agree with you on this. Actually the JVM has some information about
which reference is null when the NPE is thrown. It's reasonable if this kind
of information can be provided when NPE is thrown. This will save much time
for debugging.


kedar mhaswade wrote
> That aside, (and Chris's trick is nice), but if you have no access to the
> source for the offending code, life is hard in general, isn't it? Because
> if you can't have control over the source, making that source run on a
> platform where such an RFE would be perhaps fixed (a future release of the
> JDK) would be even harder, no? 

It's quite common that someone may have no access to the source code which
throws the NPE. For example, API developers may often not be able to access
user's source code, the only thing they can get are a bunch of logs.



-----
Programmer
--
View this message in context: http://openjdk.5641.n7.nabble.com/Useful-message-about-NullPointerException-tp213240p213867.html
Sent from the OpenJDK Core Libraries mailing list archive at Nabble.com.



More information about the core-libs-dev mailing list