[#1708] Correctly set the writerIndex in ReadOnlyByteBufferBuf if it is constructed with a buffer which has non zero position

This commit is contained in:
Norman Maurer 2013-08-08 06:54:32 +02:00
parent b934b6009c
commit 194b64cff1
2 changed files with 11 additions and 1 deletions

View File

@ -45,7 +45,7 @@ class ReadOnlyByteBufferBuf extends AbstractReferenceCountedByteBuf {
this.allocator = allocator;
this.buffer = buffer.slice().order(ByteOrder.BIG_ENDIAN);
writerIndex(buffer.limit());
writerIndex(this.buffer.limit());
leak = leakDetector.open(this);
}

View File

@ -184,4 +184,14 @@ public class ReadOnlyDirectByteBufferBufTest {
Assert.assertEquals(buf.slice(1, 9), copy);
}
// Test for https://github.com/netty/netty/issues/1708
@Test
public void testWrapBufferWithNonZeroPosition() {
ByteBuf buf = buffer(((ByteBuffer) allocate(16).putLong(1).flip().position(1)).asReadOnlyBuffer());
buffers.add(buf);
ByteBuf slice = buf.slice();
Assert.assertEquals(buf, slice);
}
}