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:
Norman Maurer 2020-02-08 17:05:26 +01:00 committed by GitHub
parent a308ac94cd
commit a3e5e4876c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View File

@ -49,7 +49,7 @@ final class FixedCompositeByteBuf extends AbstractReferenceCountedByteBuf {
order = ByteOrder.BIG_ENDIAN; order = ByteOrder.BIG_ENDIAN;
nioBufferCount = 1; nioBufferCount = 1;
capacity = 0; capacity = 0;
direct = false; direct = Unpooled.EMPTY_BUFFER.isDirect();
} else { } else {
ByteBuf b = buffers[0]; ByteBuf b = buffers[0];
this.buffers = buffers; this.buffers = buffers;

View File

@ -432,10 +432,12 @@ public class FixedCompositeByteBufTest {
} }
@Test @Test
public void testHasArrayWhenEmpty() { public void testHasArrayWhenEmptyAndIsDirect() {
ByteBuf buf = newBuffer(new ByteBuf[0]); ByteBuf buf = newBuffer(new ByteBuf[0]);
assertTrue(buf.hasArray()); assertTrue(buf.hasArray());
assertArrayEquals(EMPTY_BUFFER.array(), buf.array()); assertArrayEquals(EMPTY_BUFFER.array(), buf.array());
assertEquals(EMPTY_BUFFER.isDirect(), buf.isDirect());
assertEquals(EMPTY_BUFFER.memoryAddress(), buf.memoryAddress());
buf.release(); buf.release();
} }