[#1454] Fix IndexOutOfBoundsException which was thrown if last component of a CompositeByteBuf was removed

This commit is contained in:
Norman Maurer 2013-06-21 16:38:37 +02:00
parent e8ea98017f
commit 58b968b603
2 changed files with 14 additions and 0 deletions

View File

@ -278,6 +278,10 @@ public class DefaultCompositeByteBuf extends AbstractReferenceCountedByteBuf imp
}
private void updateComponentOffsets(int cIndex) {
if (components.isEmpty()) {
return;
}
Component c = components.get(cIndex);
if (cIndex == 0) {
c.offset = 0;

View File

@ -24,6 +24,7 @@ import java.util.Collections;
import java.util.List;
import static io.netty.buffer.Unpooled.*;
import static io.netty.buffer.Unpooled.wrappedBuffer;
import static io.netty.util.internal.EmptyArrays.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
@ -543,4 +544,13 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
assertThat(nioBuffers[1].remaining(), is(1));
assertThat(nioBuffers[1].get(), is((byte) 3));
}
@Test
public void testRemoveLastComponent() {
CompositeByteBuf buf = freeLater(compositeBuffer());
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
assertEquals(1, buf.numComponents());
buf.removeComponent(0);
assertEquals(0, buf.numComponents());
}
}