Am 09.02.2018 um 23:06 schrieb Mark Tanner:
hey all

Java has quite strict enforcement of exception handling. I.e. if a method can 
throw an exception then the calling method must handle it, and you get plenty 
of compiler warnings telling you such.

We can avoid NPE's by avoiding returning null from methods completely, and 
throwing an exception instead.

This will also allow us to customize the message of the exception and let the 
user know why they aren't getting their expected results.

Many nulls are returned by our methods because an optional item doesn't exist. So it isn't abnormal, so an exception wouldn't make sense.


Any thoughts?

Mark Tanner
From: Tilman Hausherr []
Sent: 09 February 2018 18:50
Subject: Re: [DISCUSS] return values for functions

Am 09.02.2018 um 19:20 schrieb Andreas Lehmkuehler:
Am 17.01.2018 um 18:41 schrieb Maruan Sahyoun:

many of our methods return null in case an entry can not be found
potentially causing NPEs. For 3.0 what about starting to change that
so we return the expected object in the PDModel although I understand
that this might mean that for some time some methods might return
null where others might return the expected object.

E.g. in PDAnnotationTextMarkup.getQuadPoints() in the unlikely case
that there is no sufficient entry instead of return null we could
return an empty float[].

Wouldn't expect that we start looking for such cases but doing it as
we touch methods.

I never thought about that. What exactly is the advantage of this
strategy? In the end I'm doing "is empty checks" instead of "is not
null checks".

It's a programming style that is expected to avoid NPEs, Sonar mentions
it at some places. The advantage is that you could run a loop on the
result without null checking.


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to