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 [mailto:gil...@harfang.homelinux.org] 
Sent: Thursday, September 13, 2012 10:36 AM
To: dev@commons.apache.org
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
towards
> 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
promise
>     is a CM bug.]
>  2. CM to never check for null? Then we delete class
"NullArgumentException".
>     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
raising
>     a NPE.
>  3. CM to sometimes check for null? Then "NullArgumentException"
should
>     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
the
>     user's point-of-view, there is no reason to handle them in
different
>     ways since it's the exact same bug).
>     For the user, the consequence will be similar to alternative 2,
with
>     sometimes more information about the failure and sometimes
(marginally)
>     earlier detection.

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

<snip>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to