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
ab1cf37f7c
commit
f603494424
@ -630,7 +630,14 @@ 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>();
|
||||
}
|
||||
// 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.
|
||||
|
@ -1704,4 +1704,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…
x
Reference in New Issue
Block a user