[#1875] Correctly check the readerIndex when try to read a byte from AbstractByteBuf
This commit is contained in:
parent
b4fa8af079
commit
6d09e57be7
@ -559,6 +559,7 @@ public abstract class AbstractByteBuf extends ByteBuf {
|
||||
|
||||
@Override
|
||||
public byte readByte() {
|
||||
checkReadableBytes(1);
|
||||
int i = readerIndex;
|
||||
byte b = getByte(i);
|
||||
readerIndex = i + 1;
|
||||
|
@ -1935,6 +1935,13 @@ public abstract class AbstractByteBufTest {
|
||||
assertNull(cause.get());
|
||||
}
|
||||
|
||||
@Test(expected = IndexOutOfBoundsException.class)
|
||||
public void readByteThrowsIndexOutOfBoundsException() {
|
||||
final ByteBuf buffer = freeLater(newBuffer(8));
|
||||
buffer.writeByte(0);
|
||||
assertEquals((byte) 0 , buffer.readByte());
|
||||
buffer.readByte();
|
||||
}
|
||||
static final class TestGatheringByteChannel implements GatheringByteChannel {
|
||||
private final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
private final WritableByteChannel channel = Channels.newChannel(out);
|
||||
|
Loading…
Reference in New Issue
Block a user