JDK-4834738 NullPointerException: Better info
Fedor Bobin
fuudtorrentsru at gmail.com
Wed May 7 17:38:37 UTC 2014
Hello.
Any review?
Currently I work on adding such functionality to compiled code.
I understand how to obtain method name and signature (for NPE inside
compiled method). You can see my solution in this gist
https://gist.github.com/Fuud/7b401c0a408c82f09c45
It prints method info to stdout. But I do not understand how to pass this
information to implicit exception handler. Any suggestions?
Thanks.
Fedor Bobin.
2014-04-15 11:35 GMT+04:00 David Holmes <david.holmes at oracle.com>:
> On 15/04/2014 5:16 PM, Fedor Bobin wrote:
>
>> Hello.
>>
>> What is the best way to submit patch?
>> Currently you can see it at https://gist.github.com/Fuud/10709048
>>
>
> If you become a regular contributor to OpenJDK you can get access to
> cr.openjdk.java.net to upload patches. Otherwise inline attachments or a
> link to something like github is okay.
>
>
> 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.
>>
>
> There have been a couple of RFEs on this in the past, one very recently,
> and they have been closed as "will not fix" - mainly because except in some
> limited circumstances the VM does not have much additional information to
> add. That said your patch is the "inverse" of the other requests - they
> wanted to know which "variable" was null, whereas you are showing which
> method invocation was attempted on a null reference.
>
> Hopefully some folks from the runtime team will be able to take a look at
> this and evaluate it. But it would be nice to be able to get similar
> information from compiled code too - though that may not be feasible.
>
> Thanks,
> David
>
>
>> Thanks.
>> Fedor Bobin
>>
>>
>>
>> 2014-04-15 10:32 GMT+04:00 David Holmes <david.holmes at oracle.com
>> <mailto: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