Fix IndexOutOfBoundsException when FixedCompositeByteBuf is constructed with an empty array.

Motivation:

When FixedCompositeByteBuf was constructed with new ByteBuf[0] and IndexOutOfboundsException was thrown.

Modifications:

Fix constructor

Result:

No more exception
This commit is contained in:
Norman Maurer 2016-04-11 11:52:32 +02:00
parent 4ddb81f36f
commit 7d3ca7fb92
2 changed files with 7 additions and 1 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 = buffers[0].isDirect(); direct = false;
} else { } else {
ByteBuf b = buffers[0]; ByteBuf b = buffers[0];
this.buffers = new Object[buffers.length]; this.buffers = new Object[buffers.length];

View File

@ -314,4 +314,10 @@ public class FixedCompositeByteBufTest {
assertEquals(1, byteBuffers[2].limit()); assertEquals(1, byteBuffers[2].limit());
composite.release(); composite.release();
} }
@Test
public void testEmptyArray() {
ByteBuf buf = newBuffer(new ByteBuf[0]);
buf.release();
}
} }