FixedCompositeByteBuf.isDirect() may return wrong value when constructed with empty array (#10005)
Motivation: FixedCompositeByteBuf.isDirect() should return the same value as EMPTY_BUFFER.isDirect() when constructed via an empty array Modifications: - Return correct value when constructed via empty array. - Add unit test Result: FixedCompositeByteBuf.isDirect() returns correct value
This commit is contained in:
parent
2c3833472a
commit
8ab4adcc56
@ -49,7 +49,7 @@ final class FixedCompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
||||
order = ByteOrder.BIG_ENDIAN;
|
||||
nioBufferCount = 1;
|
||||
capacity = 0;
|
||||
direct = false;
|
||||
direct = Unpooled.EMPTY_BUFFER.isDirect();
|
||||
} else {
|
||||
ByteBuf b = buffers[0];
|
||||
this.buffers = buffers;
|
||||
|
@ -432,10 +432,12 @@ public class FixedCompositeByteBufTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasArrayWhenEmpty() {
|
||||
public void testHasArrayWhenEmptyAndIsDirect() {
|
||||
ByteBuf buf = newBuffer(new ByteBuf[0]);
|
||||
assertTrue(buf.hasArray());
|
||||
assertArrayEquals(EMPTY_BUFFER.array(), buf.array());
|
||||
assertEquals(EMPTY_BUFFER.isDirect(), buf.isDirect());
|
||||
assertEquals(EMPTY_BUFFER.memoryAddress(), buf.memoryAddress());
|
||||
buf.release();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user