RFR 8135248: Add utility methods to check indexes and ranges
Stephen Colebourne
scolebourne at joda.org
Mon Sep 21 15:15:41 UTC 2015
On 21 September 2015 at 15:28, Paul Sandoz <paul.sandoz at oracle.com> wrote:
>> It would seem very worthwhile to add overloaded versions of each of
>> these methods that do not have the OutOfBoundsToException in the
>> argument list. Instead, these overloads would throw a "standard"
>> exception.
>
> That seems reasonable e.g.:
>
> public static
> int checkIndex(int index, int length) IndexOutOfBoundsException {
> return checkIndex(index, length, null);
> }
>
>> Such methods would then be much more amenable to just being
>> dropped into existing application code, where the precise exception
>> that is thrown is less of a concern.
> Though is passing “null” such a big deal?
Best to try and avoid asking application developers to pass null in to
get a special behaviour. In fact, the method could even reject null
and throw an exception, which would make more sense.
I agree with Remi on naming at least - a functional interface ending
"Exception" is likely to be confusing.
Stephen
More information about the core-libs-dev
mailing list