@Test public void handlerRemovedWillNotReleaseBufferIfDecodeInProgress() { EmbeddedChannel channel = new EmbeddedChannel(new ByteToMessageDecoder() { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { ctx.pipeline().remove(this); assertTrue(in.refCnt() != 0); } @Override protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception { assertCumulationReleased(internalBuffer()); } }); byte[] bytes = new byte[1024]; PlatformDependent.threadLocalRandom().nextBytes(bytes); assertTrue(channel.writeInbound(Unpooled.wrappedBuffer(bytes))); assertTrue(channel.finishAndReleaseAll()); }
protected ByteBuf internalBuffer() { if (cumulation != null) { return cumulation; } else { return Unpooled.EMPTY_BUFFER; } }
ByteToMessageDecoder extends ChannelInboundHandlerAdapter { protected ByteBuf internalBuffer() { if (cumulation != null) { return cumulation; } else { return Unpooled.EMPTY_BUFFER; } } }
ByteToMessageDecoder extends ChannelInboundHandlerAdapter { protected ByteBuf internalBuffer() { if (cumulation != null) { return cumulation; } else { return Unpooled.EMPTY_BUFFER; } } protected  ByteToMessageDecoder(); }
ByteToMessageDecoder extends ChannelInboundHandlerAdapter { protected ByteBuf internalBuffer() { if (cumulation != null) { return cumulation; } else { return Unpooled.EMPTY_BUFFER; } } protected  ByteToMessageDecoder(); void setSingleDecode(boolean singleDecode); boolean isSingleDecode(); void setCumulator(Cumulator cumulator); void setDiscardAfterReads(int discardAfterReads); @Override final void handlerRemoved(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void userEventTriggered(ChannelHandlerContext ctx, Object evt); }
ByteToMessageDecoder extends ChannelInboundHandlerAdapter { protected ByteBuf internalBuffer() { if (cumulation != null) { return cumulation; } else { return Unpooled.EMPTY_BUFFER; } } protected  ByteToMessageDecoder(); void setSingleDecode(boolean singleDecode); boolean isSingleDecode(); void setCumulator(Cumulator cumulator); void setDiscardAfterReads(int discardAfterReads); @Override final void handlerRemoved(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void userEventTriggered(ChannelHandlerContext ctx, Object evt); static final Cumulator MERGE_CUMULATOR; static final Cumulator COMPOSITE_CUMULATOR; }