RFR(L): 8218628: Add detailed message to NullPointerException describing what is null.
peter.levart at gmail.com
Fri Mar 29 15:43:57 UTC 2019
On 3/29/19 4:36 PM, Peter Levart wrote:
> On 3/29/19 8:49 AM, Lindenmaier, Goetz wrote:
>> So I want to withdraw my claim that NPEs are thrown frequently.
>> Probably I was biased by my compiler construction background,
>> remembering NPE checks are all over the place in the code.
>> But I think I can still keep the claim that the message is
>> printed rarely.
>> I'll adapt the JEP saying something like this:
>> "While exceptions are supposed to be thrown rarely, i.e., only
>> In exceptional situations, most are swallowed without ever
>> looking at the message. Thus, overhead in getMessage() will
>> not fall into account."
> Is this really a realistic assumption? That NPE exceptions are mostly
> swallowed in most programs despite the fact that swallowing exceptions
> (and throwing them to control the flow) is an anti-pattern? Is
> majority of code really so badly written? I would expect that most
> programs contain an exception handler of some kind that at least logs
> all unexpected exceptions.
> I think JDK should assume that NPEs are not frequent in most well
> written programs. Because in well written programs all unexpected
> exceptions are at least logged somewhere and this alone guarantees
> that programs are eventually "fixed" to not throw them frequently...
> Regards, Peter
So I would say that there are two kinds of programs (which kind is in
majority doesn't matter):
a - programs that throw and catch exceptions for exceptional situations
only (i.e. non frequently) - they also print the exceptions' messages
b - programs that throw and swallow exceptions frequently, but they
mostly don't print their messages
In either case .getMessage() is not called frequently for kind (a) and
hopefully also for kind (b).
More information about the hotspot-runtime-dev