Make sure CompositeChanneBuffer does not throw a UnsupportedOperationException if discardReadBytes() discard the whole content of the buffer. See #325

This commit is contained in:
norman 2012-05-15 13:59:33 +02:00 committed by Trustin Lee
parent a5a76131e6
commit a8d63a4ad7
2 changed files with 17 additions and 0 deletions

View File

@ -655,6 +655,15 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
final int bytesToMove = capacity() - localReaderIndex;
List<ChannelBuffer> list = decompose(localReaderIndex, bytesToMove);
// If the list is empty we need to assign a new one because
// we get a List that is immutable.
//
// See https://github.com/netty/netty/issues/325
if (list.isEmpty()) {
list = new ArrayList<ChannelBuffer>(1);
}
// Add a new buffer so that the capacity of this composite buffer does
// not decrease due to the discarded components.
// XXX Might create too many components if discarded by small amount.

View File

@ -1641,4 +1641,12 @@ public abstract class AbstractChannelBufferTest {
assertFalse(set.contains(elemB));
assertEquals(0, set.size());
}
// Test case for https://github.com/netty/netty/issues/325
@Test
public void testDiscardAllReadBytes() {
buffer.writerIndex(buffer.capacity());
buffer.readerIndex(buffer.writerIndex());
buffer.discardReadBytes();
}
}