From 44d91631690b816ca079f7db0a2359b2cd7ffcc2 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 15 Aug 2014 09:54:32 -0700 Subject: [PATCH] Fix a bug where ChannelOutboundBuffer.removeBytes() throws ClassCastException When a ChannelOutboundBuffer contains ByteBufs followed by a FileRegion, removeBytes() will fail with a ClassCastException. It should break the loop instead. --- .../main/java/io/netty/channel/ChannelOutboundBuffer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java index cdfeb7aaf7..e41b3724f6 100644 --- a/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java +++ b/transport/src/main/java/io/netty/channel/ChannelOutboundBuffer.java @@ -304,11 +304,13 @@ public final class ChannelOutboundBuffer { */ public void removeBytes(long writtenBytes) { for (;;) { - final ByteBuf buf = (ByteBuf) current(); - if (buf == null) { + Object msg = current(); + if (!(msg instanceof ByteBuf)) { + assert writtenBytes == 0; break; } + final ByteBuf buf = (ByteBuf) msg; final int readerIndex = buf.readerIndex(); final int readableBytes = buf.writerIndex() - readerIndex;