From 56bfa22d4a4850491d96238a2dd28d29ba20e70c Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 9 Mar 2021 12:02:46 +0100 Subject: [PATCH] Align Buffer.get* bounds checks with their documented behaviour The get* methods bounds checking accesses between 0 and the write offset, and the tests were confirming this behaviour. This was wrong because it is not symmetric with the set* methods, which bounds check between 0 and the capacity, and does not modify the write offset. The tests and methods have been updated so the get* methods now bounds check between 0 and the capacity. --- .../io/netty/buffer/api/CompositeBuffer.java | 35 +- .../netty/buffer/api/memseg/MemSegBuffer.java | 30 +- .../java/io/netty/buffer/api/BufferTest.java | 524 +++++++++++++++--- 3 files changed, 486 insertions(+), 103 deletions(-) diff --git a/src/main/java/io/netty/buffer/api/CompositeBuffer.java b/src/main/java/io/netty/buffer/api/CompositeBuffer.java index 5823f05..460045a 100644 --- a/src/main/java/io/netty/buffer/api/CompositeBuffer.java +++ b/src/main/java/io/netty/buffer/api/CompositeBuffer.java @@ -877,7 +877,7 @@ final class CompositeBuffer extends RcSupport implement @Override public byte getByte(int roff) { - return prepRead(roff, Byte.BYTES).getByte(subOffset); + return prepGet(roff, Byte.BYTES).getByte(subOffset); } @Override @@ -887,7 +887,7 @@ final class CompositeBuffer extends RcSupport implement @Override public int getUnsignedByte(int roff) { - return prepRead(roff, Byte.BYTES).getUnsignedByte(subOffset); + return prepGet(roff, Byte.BYTES).getUnsignedByte(subOffset); } @Override @@ -921,7 +921,7 @@ final class CompositeBuffer extends RcSupport implement @Override public char getChar(int roff) { - return prepRead(roff, 2).getChar(subOffset); + return prepGet(roff, 2).getChar(subOffset); } @Override @@ -943,7 +943,7 @@ final class CompositeBuffer extends RcSupport implement @Override public short getShort(int roff) { - return prepRead(roff, Short.BYTES).getShort(subOffset); + return prepGet(roff, Short.BYTES).getShort(subOffset); } @Override @@ -953,7 +953,7 @@ final class CompositeBuffer extends RcSupport implement @Override public int getUnsignedShort(int roff) { - return prepRead(roff, Short.BYTES).getUnsignedShort(subOffset); + return prepGet(roff, Short.BYTES).getUnsignedShort(subOffset); } @Override @@ -987,7 +987,7 @@ final class CompositeBuffer extends RcSupport implement @Override public int getMedium(int roff) { - return prepRead(roff, 3).getMedium(subOffset); + return prepGet(roff, 3).getMedium(subOffset); } @Override @@ -997,7 +997,7 @@ final class CompositeBuffer extends RcSupport implement @Override public int getUnsignedMedium(int roff) { - return prepRead(roff, 3).getMedium(subOffset); + return prepGet(roff, 3).getMedium(subOffset); } @Override @@ -1031,7 +1031,7 @@ final class CompositeBuffer extends RcSupport implement @Override public int getInt(int roff) { - return prepRead(roff, Integer.BYTES).getInt(subOffset); + return prepGet(roff, Integer.BYTES).getInt(subOffset); } @Override @@ -1041,7 +1041,7 @@ final class CompositeBuffer extends RcSupport implement @Override public long getUnsignedInt(int roff) { - return prepRead(roff, Integer.BYTES).getUnsignedInt(subOffset); + return prepGet(roff, Integer.BYTES).getUnsignedInt(subOffset); } @Override @@ -1075,7 +1075,7 @@ final class CompositeBuffer extends RcSupport implement @Override public float getFloat(int roff) { - return prepRead(roff, Float.BYTES).getFloat(subOffset); + return prepGet(roff, Float.BYTES).getFloat(subOffset); } @Override @@ -1097,7 +1097,7 @@ final class CompositeBuffer extends RcSupport implement @Override public long getLong(int roff) { - return prepRead(roff, Long.BYTES).getLong(subOffset); + return prepGet(roff, Long.BYTES).getLong(subOffset); } @Override @@ -1119,7 +1119,7 @@ final class CompositeBuffer extends RcSupport implement @Override public double getDouble(int roff) { - return prepRead(roff, Double.BYTES).getDouble(subOffset); + return prepGet(roff, Double.BYTES).getDouble(subOffset); } @Override @@ -1242,6 +1242,17 @@ final class CompositeBuffer extends RcSupport implement } } + private BufferAccessors prepGet(int index, int size) { + checkGetBounds(index, size); + return chooseBuffer(index, size); + } + + private void checkGetBounds(int index, int size) { + if (index < 0 || capacity < index + size) { + throw indexOutOfBounds(index, false); + } + } + private BufferAccessors prepWrite(int size) { var buf = prepWrite(woff, size); woff += size; diff --git a/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java b/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java index 4514f35..9d3cfdc 100644 --- a/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java +++ b/src/main/java/io/netty/buffer/api/memseg/MemSegBuffer.java @@ -589,7 +589,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public byte getByte(int roff) { - checkRead(roff, Byte.BYTES); + checkGet(roff, Byte.BYTES); return getByteAtOffset(seg, roff); } @@ -603,7 +603,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public int getUnsignedByte(int roff) { - checkRead(roff, Byte.BYTES); + checkGet(roff, Byte.BYTES); return getByteAtOffset(seg, roff) & 0xFF; } @@ -659,7 +659,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public char getChar(int roff) { - checkRead(roff, 2); + checkGet(roff, 2); return getCharAtOffset(seg, roff, order); } @@ -694,7 +694,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public short getShort(int roff) { - checkRead(roff, Short.BYTES); + checkGet(roff, Short.BYTES); return getShortAtOffset(seg, roff, order); } @@ -708,7 +708,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public int getUnsignedShort(int roff) { - checkRead(roff, Short.BYTES); + checkGet(roff, Short.BYTES); return getShortAtOffset(seg, roff, order) & 0xFFFF; } @@ -770,7 +770,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public int getMedium(int roff) { - checkRead(roff, 3); + checkGet(roff, 3); return order == ByteOrder.BIG_ENDIAN? getByteAtOffset(seg, roff) << 16 | (getByteAtOffset(seg, roff + 1) & 0xFF) << 8 | @@ -796,7 +796,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public int getUnsignedMedium(int roff) { - checkRead(roff, 3); + checkGet(roff, 3); return order == ByteOrder.BIG_ENDIAN? (getByteAtOffset(seg, roff) << 16 | (getByteAtOffset(seg, roff + 1) & 0xFF) << 8 | @@ -878,7 +878,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public int getInt(int roff) { - checkRead(roff, Integer.BYTES); + checkGet(roff, Integer.BYTES); return getIntAtOffset(seg, roff, order); } @@ -892,7 +892,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public long getUnsignedInt(int roff) { - checkRead(roff, Integer.BYTES); + checkGet(roff, Integer.BYTES); return getIntAtOffset(seg, roff, order) & 0xFFFFFFFFL; } @@ -948,7 +948,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public float getFloat(int roff) { - checkRead(roff, Float.BYTES); + checkGet(roff, Float.BYTES); return getFloatAtOffset(seg, roff, order); } @@ -983,7 +983,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public long getLong(int roff) { - checkRead(roff, Long.BYTES); + checkGet(roff, Long.BYTES); return getLongAtOffset(seg, roff, order); } @@ -1018,7 +1018,7 @@ class MemSegBuffer extends RcSupport implements Buffer, Re @Override public double getDouble(int roff) { - checkRead(roff, Double.BYTES); + checkGet(roff, Double.BYTES); return getDoubleAtOffset(seg, roff, order); } @@ -1093,6 +1093,12 @@ class MemSegBuffer extends RcSupport implements Buffer, Re } } + private void checkGet(int index, int size) { + if (index < 0 || seg.byteSize() < index + size) { + throw readAccessCheckException(index); + } + } + private void checkWrite(int index, int size) { if (index < 0 || wseg.byteSize() < index + size) { throw writeAccessCheckException(index); diff --git a/src/test/java/io/netty/buffer/api/BufferTest.java b/src/test/java/io/netty/buffer/api/BufferTest.java index 1cdffeb..b10e262 100644 --- a/src/test/java/io/netty/buffer/api/BufferTest.java +++ b/src/test/java/io/netty/buffer/api/BufferTest.java @@ -3215,19 +3215,37 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfByteMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getByte(0)); + buf.getByte(0); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfByteMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getByte(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.getByte(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfByteReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getByte(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getByte(8)); } } @@ -3343,42 +3361,79 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedByteMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x01; buf.writeUnsignedByte(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(1)); + buf.getUnsignedByte(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( + void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedByteReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x01; buf.writeUnsignedByte(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(1)); + buf.readOnly(true).getUnsignedByte(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity( + Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(8)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedByteMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(0)); + buf.getUnsignedByte(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedByteMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedByte(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedByteReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getUnsignedByte(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedByteReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedByte(8)); } } @@ -3660,41 +3715,77 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfCharMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfCharMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { char value = 0x0102; buf.writeChar(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(1)); + buf.getChar(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfCharMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfCharReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { char value = 0x0102; buf.writeChar(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(1)); + buf.readOnly(true).getChar(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfCharMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(7)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfCharMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(0)); + buf.getChar(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfCharMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getChar(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfCharReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getChar(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfCharReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getChar(8)); } } @@ -3893,41 +3984,77 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfShortMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { short value = 0x0102; buf.writeShort(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(1)); + buf.getShort(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfShortReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { short value = 0x0102; buf.writeShort(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(1)); + buf.readOnly(true).getShort(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(7)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfShortMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(0)); + buf.getShort(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfShortMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getShort(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfShortReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getShort(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getShort(7)); } } @@ -4043,42 +4170,79 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedShortMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x0102; buf.writeUnsignedShort(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(1)); + buf.getUnsignedShort(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( + void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedShortReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x0102; buf.writeUnsignedShort(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(1)); + buf.readOnly(true).getUnsignedShort(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity( + Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(7)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedShortMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(0)); + buf.getUnsignedShort(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedShortMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedShort(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedShortReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getUnsignedShort(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedShortReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedShort(7)); } } @@ -4360,32 +4524,70 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeMedium(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(1)); + buf.getMedium(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeMedium(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(1)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(6)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfMediumReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(0)); + int value = 0x010203; + buf.writeMedium(value); + buf.readOnly(true).getMedium(1); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(6)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfMediumMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.getMedium(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfMediumMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getMedium(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfMediumReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getMedium(0); } } @@ -4394,7 +4596,7 @@ public class BufferTest { void offsettedGetOfMediumReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getMedium(8)); } } @@ -4510,42 +4712,79 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeUnsignedMedium(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(1)); + buf.getUnsignedMedium(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( + void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(6)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedMediumReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { int value = 0x010203; buf.writeUnsignedMedium(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(1)); + buf.readOnly(true).getUnsignedMedium(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity( + Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(6)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedMediumMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(0)); + buf.getUnsignedMedium(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedMediumMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedMedium(6)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedMediumReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getUnsignedMedium(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedMediumReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedMedium(8)); } } @@ -4849,19 +5088,37 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfIntMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getInt(0)); + buf.getInt(0); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfIntMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getInt(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.getInt(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfIntReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getInt(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getInt(8)); } } @@ -4977,42 +5234,79 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedIntMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { long value = 0x01020304; buf.writeUnsignedInt(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(1)); + buf.getUnsignedInt(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( + void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(5)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedIntReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset( Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { long value = 0x01020304; buf.writeUnsignedInt(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(1)); + buf.readOnly(true).getUnsignedInt(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity( + Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(5)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfUnsignedIntMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(0)); + buf.getUnsignedInt(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedIntMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getUnsignedInt(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedIntReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getUnsignedInt(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfUnsignedIntReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getUnsignedInt(8)); } } @@ -5294,41 +5588,77 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfFloatMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(1)); + buf.getFloat(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(7)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfFloatReadOnlyMustNotBoundsCheckWhenReadOffsetAndSizeIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { float value = Float.intBitsToFloat(0x01020304); buf.writeFloat(value); - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(1)); + buf.readOnly(true).getFloat(1); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetAndSizeIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(5)); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfFloatMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(0)); + buf.getFloat(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfFloatMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.getFloat(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfFloatReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getFloat(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfFloatReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThan(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getFloat(8)); } } @@ -5549,19 +5879,37 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfLongMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfLongMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getLong(0)); + buf.getLong(0); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfLongReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfLongMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getLong(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.getLong(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfLongReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getLong(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfLongReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getLong(8)); } } @@ -5782,19 +6130,37 @@ public class BufferTest { @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfDoubleMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfDoubleMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.getDouble(0)); + buf.getDouble(0); } } @ParameterizedTest @MethodSource("allocators") - void offsettedGetOfDoubleReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + void offsettedGetOfDoubleMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { try (BufferAllocator allocator = fixture.createAllocator(); Buffer buf = allocator.allocate(8)) { - assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getDouble(0)); + assertThrows(IndexOutOfBoundsException.class, () -> buf.getDouble(8)); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfDoubleReadOnlyMustNotBoundsCheckWhenReadOffsetIsGreaterThanWriteOffset(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + buf.readOnly(true).getDouble(0); + } + } + + @ParameterizedTest + @MethodSource("allocators") + void offsettedGetOfDoubleReadOnlyMustBoundsCheckWhenReadOffsetIsGreaterThanCapacity(Fixture fixture) { + try (BufferAllocator allocator = fixture.createAllocator(); + Buffer buf = allocator.allocate(8)) { + assertThrows(IndexOutOfBoundsException.class, () -> buf.readOnly(true).getDouble(8)); } }