@Test public void decodeWithErrorDoesntRetainExtraCopy() throws Exception { ByteBuf input = Unpooled.buffer(TFrame.FRAME_SIZE_LENGTH); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); assertEquals(1, input.refCnt()); try { new TFrameCodec().decode(ctx, input, new ArrayList<Object>()); fail(); } catch (IndexOutOfBoundsException e) { assertTrue(e .getMessage() .contains( "readerIndex(0) + length(2) exceeds writerIndex(0): ")); } assertEquals(1, input.refCnt()); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { msg.retain(); boolean release = true; try { out.add(decode(msg)); release = false; } finally { if (release) { msg.release(); } } }
TFrameCodec extends ByteToMessageCodec<TFrame> { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { msg.retain(); boolean release = true; try { out.add(decode(msg)); release = false; } finally { if (release) { msg.release(); } } } }
TFrameCodec extends ByteToMessageCodec<TFrame> { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { msg.retain(); boolean release = true; try { out.add(decode(msg)); release = false; } finally { if (release) { msg.release(); } } }  }
TFrameCodec extends ByteToMessageCodec<TFrame> { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { msg.retain(); boolean release = true; try { out.add(decode(msg)); release = false; } finally { if (release) { msg.release(); } } }  static ByteBuf encode(ByteBufAllocator allocator, TFrame frame); static TFrame decode(ByteBuf buffer); }
TFrameCodec extends ByteToMessageCodec<TFrame> { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { msg.retain(); boolean release = true; try { out.add(decode(msg)); release = false; } finally { if (release) { msg.release(); } } }  static ByteBuf encode(ByteBufAllocator allocator, TFrame frame); static TFrame decode(ByteBuf buffer);  }