On Wed, Mar 4, 2020 at 7:58 AM sebb <seb...@gmail.com> wrote:

> On Sat, 29 Feb 2020 at 18:09, Gilles Sadowski <gillese...@gmail.com>
> wrote:
> >
> > Le sam. 29 févr. 2020 à 18:39, Gary Gregory <garydgreg...@gmail.com> a
> écrit :
> > >
> > > On Sat, Feb 22, 2020 at 5:25 PM Gary Gregory <garydgreg...@gmail.com>
> wrote:
> > >
> > > > I would like to do the same in Lang as with Collections (see below.)\
> > > >
> > > > We currently perform checks like:
> > > >
> > > > Validate.isTrue(foo != null, ...)
> > > >
> > > > Which should be IMO:
> > > >
> > > > Validate.notNull(foo, ...);
> > > >
> > > > The difference being that the former throws IAE and the later NPE.
> > > >
> > > > As with [collections], my argument is the same, the JRE uses
> > > > Objects.requireNonNull() to throw an NPE, so I'd like to keep
> normalizing
> > > > on that.
> > > >
> > >
> > > Any thoughts? Should I proceed?
> >
>
> +1
>
> > +1 for NPE on unexpected null.
> > [But perhaps it is not necessary to double-check, as the JRE
> > will do it anyway (and throw NPE).]
>

This is not about dropping the check, please re-read the thread,
specifically:

We currently perform checks like:

Validate.isTrue(foo != null, ...)

Which should be IMO:

Validate.notNull(foo, ...);

notNull calls the JRE's Objects.requireNonNull()


> Depends on how and where the variable is used -- sometimes a null can
> cause hard to track errors, not necessarily NPE, and the exception (or
> possibly other failure) may be a long way from the initial method
> call.
>
> It's almost always better to report the problem as early as possible.
>
> I think the existing checks should be kept.
>

Agreed, but I am talking but performing a better cleaner check by using
Validate.notNull(foo, ...) instead of  Validate.isTrue(foo != null, ...)

Gary


>
> If it can be proved that the code would generate NPE immediately
> anyway, it might be worth dropping the check.
> However, code changes, so at least a comment should be left in its
> place to note that the code is relying on Java to generate the NPE at
> this point.
>

> > Gilles
> >
> > >
> > > Gary
> > >
> > >
> > > >
> > > > Gary
> > > >
> > > > ---------- Forwarded message ---------
> > > > From: Gary Gregory <garydgreg...@gmail.com>
> > > > Date: Tue, Dec 10, 2019 at 9:59 AM
> > > > Subject: Re: [collection] NPE vs IAE in
> > > > org.apache.commons.collections4.CollectionUtils
> > > > To: Commons Developers List <dev@commons.apache.org>, Bruno P.
> Kinoshita <
> > > > brunodepau...@yahoo.com.br>
> > > >
> > > >
> > > > FTR, using requireNonNull is also an 'Effective Java' recommendation.
> > > >
> > > > Gary
> > > >
> > > > On Thu, Dec 5, 2019 at 4:54 PM Bruno P. Kinoshita
> > > > <brunodepau...@yahoo.com.br.invalid> wrote:
> > > >
> > > >>  +1 for NPE
> > > >>
> > > >>     On Friday, 6 December 2019, 5:22:34 am NZDT, Gary Gregory <
> > > >> garydgreg...@gmail.com> wrote:
> > > >>
> > > >>  Hi All:
> > > >>
> > > >> org.apache.commons.collections4.CollectionUtils contains a mix of
> checking
> > > >> for null inputs by throwing NullPointerExceptions in some methods
> and
> > > >> IllegalArgumentExceptions in others.
> > > >>
> > > >> I propose we standardized to NPE simply because the JRE provides
> > > >> Objects.requireNonNull() just for this purpose.
> > > >>
> > > >> Gary
> > > >>
> > > >
> > > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> > For additional commands, e-mail: dev-h...@commons.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
> For additional commands, e-mail: dev-h...@commons.apache.org
>
>

Reply via email to