[#1708] Correctly set the writerIndex in ReadOnlyByteBufferBuf if it is constructed with a buffer which has non zero position
This commit is contained in:
parent
b934b6009c
commit
194b64cff1
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user