@Test void newCumulationBufferShouldNotThrowOnNegativeSize() { ChannelHandlerContext channelHandler = mock(ChannelHandlerContext.class); Channel channel = mock(Channel.class); ChannelConfig channelConfig = mock(ChannelConfig.class); when(channelConfig.getBufferFactory()).thenReturn(mock(ChannelBufferFactory.class)); when(channelHandler.getChannel()).thenReturn(channel); when(channel.getConfig()).thenReturn(channelConfig); when(channelHandler.getAttachment()).thenReturn(ImmutableMap.<String, Object>of(NEEDED_DATA, -1)); assertThatCode(() -> testee.newCumulationBuffer(channelHandler, 36)) .doesNotThrowAnyException(); }
@Override protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) { Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment(); Object sizeAsObject = attachment.get(NEEDED_DATA); if (sizeAsObject != null) { @SuppressWarnings("unchecked") int size = (Integer) sizeAsObject; if (size > 0) { int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit); int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size); return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory()); } } return super.newCumulationBuffer(ctx, minimumCapacity); }
ImapRequestFrameDecoder extends FrameDecoder implements NettyConstants { @Override protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) { Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment(); Object sizeAsObject = attachment.get(NEEDED_DATA); if (sizeAsObject != null) { @SuppressWarnings("unchecked") int size = (Integer) sizeAsObject; if (size > 0) { int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit); int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size); return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory()); } } return super.newCumulationBuffer(ctx, minimumCapacity); } }
ImapRequestFrameDecoder extends FrameDecoder implements NettyConstants { @Override protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) { Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment(); Object sizeAsObject = attachment.get(NEEDED_DATA); if (sizeAsObject != null) { @SuppressWarnings("unchecked") int size = (Integer) sizeAsObject; if (size > 0) { int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit); int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size); return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory()); } } return super.newCumulationBuffer(ctx, minimumCapacity); } ImapRequestFrameDecoder(ImapDecoder decoder, int inMemorySizeLimit, int literalSizeLimit); }
ImapRequestFrameDecoder extends FrameDecoder implements NettyConstants { @Override protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) { Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment(); Object sizeAsObject = attachment.get(NEEDED_DATA); if (sizeAsObject != null) { @SuppressWarnings("unchecked") int size = (Integer) sizeAsObject; if (size > 0) { int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit); int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size); return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory()); } } return super.newCumulationBuffer(ctx, minimumCapacity); } ImapRequestFrameDecoder(ImapDecoder decoder, int inMemorySizeLimit, int literalSizeLimit); @Override void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e); }
ImapRequestFrameDecoder extends FrameDecoder implements NettyConstants { @Override protected synchronized ChannelBuffer newCumulationBuffer(ChannelHandlerContext ctx, int minimumCapacity) { Map<String, Object> attachment = (Map<String, Object>) ctx.getAttachment(); Object sizeAsObject = attachment.get(NEEDED_DATA); if (sizeAsObject != null) { @SuppressWarnings("unchecked") int size = (Integer) sizeAsObject; if (size > 0) { int sanitizedInMemorySizeLimit = Math.max(0, inMemorySizeLimit); int sanitizedSize = Math.min(sanitizedInMemorySizeLimit, size); return ChannelBuffers.dynamicBuffer(sanitizedSize, ctx.getChannel().getConfig().getBufferFactory()); } } return super.newCumulationBuffer(ctx, minimumCapacity); } ImapRequestFrameDecoder(ImapDecoder decoder, int inMemorySizeLimit, int literalSizeLimit); @Override void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e);  }