[#1454] Fix IndexOutOfBoundsException which was thrown if last component of a CompositeByteBuf was removed
This commit is contained in:
parent
e8ea98017f
commit
58b968b603
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user