[#1875] Correctly check the readerIndex when try to read a byte from AbstractByteBuf

This commit is contained in:
Norman Maurer 2013-09-30 14:47:49 +02:00
parent 321990a115
commit 512908f993
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -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);