RFR: 8299982: (bf) Buffer.checkIndex(int, int) should use Preconditions.checkIndex(int, int, BiFunction) [v2]
Brian Burkhalter
bpb at openjdk.org
Thu Jan 26 17:51:18 UTC 2023
On Thu, 26 Jan 2023 17:47:54 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
>> In the original code it just has `throw new IndexOutOfBoundsException();`, so why not make it non-capturing lambda by just returning the same, e.g., `(x, y) -> new IndexOutOfBoundsException()`
>
>> Hmm, maybe start out simple with a constant, otherwise this change is going to require much wider startup and performance testing.
>
> Something like?
>
> @ForceInline
> final int checkIndex(int i, int nb) { // package-private
> return Preconditions.checkIndex(i, limit - nb + 1,
> (x, y) -> new IndexOutOfBoundsException());
> }
> In the original code it just has `throw new IndexOutOfBoundsException();`, so why not make it non-capturing lambda by just returning the same, e.g., `(x, y) -> new IndexOutOfBoundsException()`
We were trying to improve the message but it looks like it is not worth it.
-------------
PR: https://git.openjdk.org/jdk/pull/12174
More information about the nio-dev
mailing list