[15] RFR: 8248476: No helpful NullPointerException message after calling fillInStackTrace

forax at univ-mlv.fr forax at univ-mlv.fr
Tue Jun 30 13:54:56 UTC 2020


----- Mail original -----
> De: "Goetz Lindenmaier" <goetz.lindenmaier at sap.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Christoph Dreis" <christoph.dreis at freenet.de>, "hotspot-runtime-dev" <hotspot-runtime-dev at openjdk.java.net>
> Envoyé: Mardi 30 Juin 2020 11:13:04
> Objet: RE: [15] RFR: 8248476: No helpful NullPointerException message after calling fillInStackTrace

> Hi Remi,
> 
> Hmm, Throwable.stackTrace is used for the stack trace at some point.

yes, it contains the Java stack trace, but if the Java stack trace is filled you don't compute any hepful message anyway.

> Another way to set a marker would be to handle it similar
> to the hidden_top_frames in javaClasses.cpp.
> Anyways, there are other places where the message is omitted,
> e.g. in case of a hidden top frame.
> 
> Remi, as we agree that the proposed solution is the
> most handy one, can I count you as reviewer?

yes, but it will not be enough to commit given that i don't have the status of 'Reviewer' for the jdk project,
you need someone else.

> 
> Best regards,
>  Goetz.

regards,
Rémi

> 
> 
> 
> 
>> -----Original Message-----
>> From: Remi Forax <forax at univ-mlv.fr>
>> Sent: Tuesday, June 30, 2020 9:54 AM
>> To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com>
>> Cc: Christoph Dreis <christoph.dreis at freenet.de>; hotspot-runtime-dev
>> <hotspot-runtime-dev at openjdk.java.net>
>> Subject: Re: [15] RFR: 8248476: No helpful NullPointerException message
>> after calling fillInStackTrace
>> 
>> ----- Mail original -----
>> > De: "Goetz Lindenmaier" <goetz.lindenmaier at sap.com>
>> > À: "Christoph Dreis" <christoph.dreis at freenet.de>, "hotspot-runtime-dev"
>> <hotspot-runtime-dev at openjdk.java.net>
>> > Envoyé: Lundi 29 Juin 2020 14:07:08
>> > Objet: RE: [15] RFR: 8248476: No helpful NullPointerException message
>> after calling fillInStackTrace
>> 
>> [...]
>> 
>> > An alternative fix I could imagine would be to
>> > override fillInStackTrace in NPE.java. It could
>> > call getMessage() and then super.fillInStackTrace,
>> > and return a new exception with the message.
>> 
>> overriding fillInStackTrace() and marking it when it is called twice is the
>> other
>> solution.
>> 
>> > But this would also compute the message in cases where it is not printed.
>> 
>> you don't need that, you can change the field Throwable.stackTrace with a
>> marker object not unlike UNASSIGNED_STACK to detect if NPE.fillInStackTrace
>> is called twice,
>> but as is said earlier, it's not a small change because Throwable should stay
>> thread safe and serializable.
>> 
>> So i agree with you and Christoph that the "best" solution is to document
>> that null.fillInStackTrace() doesn't get a detailed error message, apart if
>> someone has a better fix.
>> 
>> >
>> > Best regards,
>> >  Goetz.
>> 
>> Rémi
>> 
>> >
>> >> -----Original Message-----
>> >> From: Christoph Dreis <christoph.dreis at freenet.de>
>> >> Sent: Monday, June 29, 2020 1:28 PM
>> >> To: Lindenmaier, Goetz <goetz.lindenmaier at sap.com>; hotspot-runtime-
>> >> dev at openjdk.java.net
>> >> Subject: Re: [15] RFR: 8248476: No helpful NullPointerException message
>> >> after calling fillInStackTrace
>> >>
>> >> Hi Goetz,
>> >>
>> >> > If changing the stack trace by calling fillInStackTrace in user code, the
>> >> > NPE algorithm lacks the proper information to compute the message.
>> >> > Thus, we must omit it after that call.
>> >>
>> >> > I implement this by checking for a call to fillInStackTrace at the bci
>> >> > recorded in the exception.
>> >> > http://cr.openjdk.java.net/~goetz/wr20/8248476-NPE_fillInStackTrace-
>> >> jdk15/01/
>> >>
>> >> I tried this when reporting the issue already. The problem with this is, that
>> it
>> >> suppresses any valid exception.
>> >>
>> >> E.g. the following example would not throw any helpful NPE anymore.
>> >>
>> >> public class Main {
>> >> 	public static void main(String[] args) {
>> >> 		NullPointerException ex = null;
>> >> 		ex.fillInStackTrace();
>> >> 	}
>> >> }
>> >>
>> >> Cheers,
>> >> Christoph


More information about the hotspot-runtime-dev mailing list