RFR: 8299982: (bf) Buffer.checkIndex(int, int) should use Objects.checkIndex(int, int)

Alan Bateman alanb at openjdk.org
Wed Jan 25 17:55:42 UTC 2023


On Tue, 24 Jan 2023 22:07:51 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Replace explicit check of indexes in `Buffer::checkIndex(int,int)` with a call to `Objects::checkIndex(int,int)` in order to improve the throughput of other methods which invoke `Buffer::checkIndex(int,int)`.

The number of byte parameter is 1, 2, 4 or 8 so limit - nb + 1 shouldn't overflow. I'm just mulling over the exception messages, e.g. `ByteBuffer.allocate(0).getChar(0)`  will throw `java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length -1`.

-------------

PR: https://git.openjdk.org/jdk/pull/12174


More information about the nio-dev mailing list