JDK-4834738 NullPointerException: Better info

Fedor Bobin fuudtorrentsru at gmail.com
Tue Apr 15 07:16:39 UTC 2014


Hello.

What is the best way to submit patch?
Currently you can see it at https://gist.github.com/Fuud/10709048

>>Can you explain what information you add?

This java code will produce NPE;

((String)null).length();

Before patch exception stack trace looks like this:

java.lang.NullPointerException
        at Test.testNPE(Test.java:14)
        at Test.main(Test.java:8)

After patch if code is executing by interpreter NPE will have additional
information

java.lang.NullPointerException: can not invoke method
java.lang.String.length()I on null object
        at Test.testNPE(Test.java:14)
        at Test.main(Test.java:8)

This additional information can help to understand cause of NPE in case of
call chains. For example, let we have java code

a.b().c();

if we get NPE without message we can not understand is a==null or
a.b()==null. After patch we will get enough information:

java.lang.NullPointerException: can not invoke method A.b() on null object

So we can understand that a is null.


Thanks.
Fedor Bobin



2014-04-15 10:32 GMT+04:00 David Holmes <david.holmes at oracle.com>:

> Hi Fedor,
>
>
> On 14/04/2014 1:09 AM, Fedor Bobin wrote:
>
>> Can you please review patch for JDK-4834738.
>>
>
> Patches are stripped when sent as attachments.
>
>
>  Currently I added more information to NPE if it is handled by interpreter
>> or template interpreter on x86-64. On other platforms and after
>> compilation
>> jdk will handle NPE as usual.
>>
>
> Can you explain what information you add?
>
> Thanks,
> David
>
>


More information about the hotspot-dev mailing list