Make sure CompositeChanneBuffer does not throw a UnsupportedOperationException if discardReadBytes() discard the whole content of the buffer. See #325
This commit is contained in:
parent
9f6cc0a0d2
commit
52a7d28cb5
@ -660,6 +660,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.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user