[#1821] Fix IndexOutOfBoundsException which was thrown if the last component was removed but other components was left
This commit is contained in:
parent
36c8ac5e5c
commit
451e91d142
@ -323,7 +323,8 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateComponentOffsets(int cIndex) {
|
private void updateComponentOffsets(int cIndex) {
|
||||||
if (components.isEmpty()) {
|
int size = components.size();
|
||||||
|
if (size <= cIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -334,7 +335,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
cIndex ++;
|
cIndex ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = cIndex; i < components.size(); i ++) {
|
for (int i = cIndex; i < size; i ++) {
|
||||||
Component prev = components.get(i - 1);
|
Component prev = components.get(i - 1);
|
||||||
Component cur = components.get(i);
|
Component cur = components.get(i);
|
||||||
cur.offset = prev.endOffset;
|
cur.offset = prev.endOffset;
|
||||||
|
@ -567,6 +567,16 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
|||||||
assertEquals(0, freeLater(buf.duplicate()).readableBytes());
|
assertEquals(0, freeLater(buf.duplicate()).readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemoveLastComponentWithOthersLeft() {
|
||||||
|
CompositeByteBuf buf = freeLater(compositeBuffer());
|
||||||
|
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
|
||||||
|
buf.addComponent(wrappedBuffer(new byte[]{1, 2}));
|
||||||
|
assertEquals(2, buf.numComponents());
|
||||||
|
buf.removeComponent(1);
|
||||||
|
assertEquals(1, buf.numComponents());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Test
|
@Test
|
||||||
public void testInternalNioBuffer() {
|
public void testInternalNioBuffer() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user