commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kish, Robert" <>
Subject RE: [Math] About "NullArgumentException"
Date Thu, 13 Sep 2012 17:34:38 GMT
Hello - 
	I've been following this mailing list for a few months, and I
feel this is a good opportunity to provide a first opinion on a topic.

I find option 2, to never check for null, the best option. But, I think
it would work even better with annotations such as package level
@NonNullByDefault, which is what CM appears to follow. For functions
that allow null, they could be tagged @Nullable.

These annotations have been made more popular by Eclipse Juno including
easier support for them, and I find in my own code, they are nice to
use. When using these annotations, any superfluous null checks inside
the CM library would trigger a compiler warning that they're not needed.

Any CM functions being called externally would be flagged that they
don't allow null values to be passed in.

In theory, we'd have compile time null checking, so no NPE at all.

Note that I'm not suggesting that these annotations be used now, but if
they were to be used one day, there would be little changes needed to CM
code (no compiler warnings to remove due to unnecessary null checks).

Robert Kish

-----Original Message-----
From: Gilles Sadowski [] 
Sent: Thursday, September 13, 2012 10:36 AM
Subject: Re: [Math] About "NullArgumentException"

On Thu, Sep 13, 2012 at 01:10:41AM +0200, Gilles Sadowski wrote:
> Hello.
> [For those who don't wish to read the whole post, please at least go
> the end and indicate your preferred option. Thanks.]
> [... long post skipped ...]
> Back to square one, with 3 fully consistent alternatives:
>  1. CM to always check for null? Then "NullArgumentException"
inheriting from
>     "MathIllegalArgumentException" is fine because we promise to the
user that
>     no NPE will ever propagate through the CM layer. [Breaking that
>     is a CM bug.]
>  2. CM to never check for null? Then we delete class
>     Users are warned by the general policy: "Do not pass null unless
it is
>     explicitly documented to be allowed." A bug will lead to the JVM
>     a NPE.
>  3. CM to sometimes check for null? Then "NullArgumentException"
>     inherit from "NullPointerException" because the user will
sometimes see
>     "NullArgumentException" (when CM checks) and sometimes NPE (when
CM does
>     not check) and both should thus belong to the same hierarchy (from
>     user's point-of-view, there is no reason to handle them in
>     ways since it's the exact same bug).
>     For the user, the consequence will be similar to alternative 2,
>     sometimes more information about the failure and sometimes
>     earlier detection.

My preference would be alternative 2 but I'd be happy with alternative 3
(as a compromise to allow checks for people who need more time to get
of the habit :-).


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

View raw message