From a0fca9312805a84c1903acd78be2e84ae88bb0e2 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 2 Apr 2013 07:17:10 +0200 Subject: [PATCH] [#1222] Correctly handle the case when a MessageToMessageEncoder encodes to ByteBuf and the next outbound buffer is of type ByteBuf --- .../io/netty/handler/codec/MessageToMessageEncoder.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java index dfe07e7739..ed6d8745e1 100644 --- a/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java +++ b/codec/src/main/java/io/netty/handler/codec/MessageToMessageEncoder.java @@ -17,6 +17,7 @@ package io.netty.handler.codec; import io.netty.buffer.MessageBuf; import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelHandlerUtil; import io.netty.channel.ChannelOutboundMessageHandlerAdapter; /** @@ -51,7 +52,11 @@ public abstract class MessageToMessageEncoder extends ChannelOutboundMessageH @Override public final void flush(ChannelHandlerContext ctx, I msg) throws Exception { try { - ctx.nextOutboundMessageBuffer().unfoldAndAdd(encode(ctx, msg)); + Object encoded = encode(ctx, msg); + // Handle special case when the encoded output is a ByteBuf and the next handler in the pipeline + // accept bytes. Related to #1222 + ChannelHandlerUtil.addToNextOutboundBuffer(ctx, encoded); + } catch (CodecException e) { throw e; } catch (Exception e) {