On Mon, 5 Dec 2022 13:22:36 GMT, Sergey Tsypanov <[email protected]> wrote:
>> Yeah, this AIOOBE is exactly the reason why I added this. So should we
>> modify `codePointBefore` in the same way as `codePointAt`?
>
> I'm asking because counter-intuitively `codePointBefore ` doesn't specify
> IOOBE for negative `index`.
>
> /**
> * @return the Unicode code point value before the given index.
> * @throws NullPointerException if {@code a} is null.
> * @throws IndexOutOfBoundsException if the {@code index}
> * argument is not greater than the {@code start} argument or
> * is greater than the length of the {@code char} array, or
> * if the {@code start} argument is negative or not less than
> * the length of the {@code char} array.
> * @since 1.5
> */
> ```
The corresponding test case for `codePointBefore` is:
callCodePoint(Before, a, a.length+1, a.length-1,
IndexOutOfBoundsException.class);
The implementation is checking that `start` does not exceed the length but it
should be checking that `index` does not exceed the length.
Since `start` must be non-negative and `index` must be greater than `start, it
follows that `index` must non-negative and then checked against the length.
-------------
PR: https://git.openjdk.org/jdk/pull/11480