JDK-4834738 NullPointerException: Better info
Staffan Larsen
staffan.larsen at oracle.com
Tue Apr 15 09:25:26 UTC 2014
On 15 apr 2014, at 09:35, David Holmes <david.holmes at oracle.com> wrote:
> 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.
I don’t feel comfortable reviewing the code, by I support the effort even if it is only for the interpreter. If at a later stage we can add the same information from the compilers, that would of course be good.
/Staffan
>
> 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