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 373b2ba4f1
commit e3aced62ed
2 changed files with 7 additions and 1 deletions

View File

@ -48,7 +48,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

@ -339,4 +339,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();
}
} }