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
parent 9f6cc0a0d2
commit 52a7d28cb5
2 changed files with 17 additions and 0 deletions

View File

@ -660,6 +660,15 @@ public class CompositeChannelBuffer extends AbstractChannelBuffer {
final int bytesToMove = capacity() - localReaderIndex; final int bytesToMove = capacity() - localReaderIndex;
List<ChannelBuffer> list = decompose(localReaderIndex, bytesToMove); 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 // Add a new buffer so that the capacity of this composite buffer does
// not decrease due to the discarded components. // not decrease due to the discarded components.
// XXX Might create too many components if discarded by small amount. // 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)); assertFalse(set.contains(elemB));
assertEquals(0, set.size()); 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();
}
} }