Is null checked or unchecked?

I think neither, so isUnchecked also needs to check for null.

I wonder whether it might be better to throw NPE in both cases for null.

It may be confusing for users if not checked != unchecked.
e.g. it is tempting to code:

if (isChecked(t)) {
} else { // must be unChecked
}

If we don’t throw NPE, then it needs to be made very clear that
isChecked and isUnchecked are not opposites, there is a 3rd case.

In any case, there needs to be a unit-test specifically for null.

Sebb

On Mon, 3 Jul 2023 at 01:29, Elliotte Rusty Harold <elh...@ibiblio.org> wrote:
>
> On Mon, Jul 3, 2023 at 12:20 AM Gary Gregory <garydgreg...@gmail.com> wrote:
> >
> > Hi Elliotte:
> >
> > Might you be looking at some old code in the PR?
> >
>
> Just looking at what was posted in the email thread. It's a weird
> corner case not everyone thinks of.
>
> > The current code is:
> >
> >     /**
> >      * Checks if a throwable represents a checked exception
> >      *
> >      * @param throwable
> >      *            The throwable to check.
> >      * @return True if the given Throwable is a checked exception.
> >      * @since 3.13.0
> >      */
> >     public static boolean isChecked(final Throwable throwable) {
> >         return throwable != null && !(throwable instanceof Error) &&
> > !(throwable instanceof RuntimeException);
> >     }
>
> This also looks wrong. This might work:
>
> public static boolean isChecked(final Throwable throwable) {
>          return throwable != null && throwable instanceof Exception &&
>  !(throwable instanceof RuntimeException);
>     }
>
>
>
> --
> Elliotte Rusty Harold
> elh...@ibiblio.org
>
> ---------------------------------------------------------------------
> 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