Skip to content

Commit

Permalink
[#1821] Fix IndexOutOfBoundsException which was thrown if the last co…
Browse files Browse the repository at this point in the history
…mponent was removed but other components was left
  • Loading branch information
Norman Maurer committed Sep 10, 2013
1 parent 12f3257 commit 3b44c60
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions buffer/src/main/java/io/netty/buffer/CompositeByteBuf.java
Expand Up @@ -323,7 +323,8 @@ private void checkComponentIndex(int cIndex, int numComponents) {
}

private void updateComponentOffsets(int cIndex) {
if (components.isEmpty()) {
int size = components.size();
if (size <= cIndex) {
return;
}

Expand All @@ -334,7 +335,7 @@ private void updateComponentOffsets(int cIndex) {
cIndex ++;
}

for (int i = cIndex; i < components.size(); i ++) {
for (int i = cIndex; i < size; i ++) {
Component prev = components.get(i - 1);
Component cur = components.get(i);
cur.offset = prev.endOffset;
Expand Down
Expand Up @@ -567,6 +567,16 @@ public void testDuplicateEmpty() {
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
@Test
public void testInternalNioBuffer() {
Expand Down

0 comments on commit 3b44c60

Please sign in to comment.