title: ReplayingDecoder throws exception on decode
body: <p>I have created an decoder to process bytes that client sends. 
  Here is it</p>
  
  <pre><code>import java.util.List;
  
  import io.netty.buffer.ByteBuf;
  import io.netty.channel.ChannelHandlerContext;
  import io.netty.handler.codec.ReplayingDecoder;
  
  public class MessageDecoder extends ReplayingDecoder&lt;DecoderState&gt; {
  
      private int length;
  
      public MessageDecoder()
      {
          super(DecoderState.READ_LENGTH);
      }
  
      @Override
      protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List&lt;Object&gt; out) throws Exception{
          System.out.println(buf.readableBytes());
          switch(state()){
              case READ_LENGTH:
                  length=buf.readInt();
                  System.out.println("length is: "+length);
                  checkpoint(DecoderState.READ_CONTENT);
              case READ_CONTENT:
                  ByteBuf frame = buf.readBytes(length);
                  checkpoint(DecoderState.READ_LENGTH);
                  out.add(frame);
                  break;
              default:
                  throw new Error("Shouldn't reach here");
          }
      }
  }
  </code></pre>
  
  <p>And it throws next error when the client sends the bytes</p>
  
  <blockquote>
    <p>io.netty.handler.codec.DecoderException: java.lang.IllegalArgumentException: minimumReadableBytes: -603652096 (expected: >= 0)
        at io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:431)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:245)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:292)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:278)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:962)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:485)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:399)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:371)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
        at java.lang.Thread.run(Unknown Source)</p>
  </blockquote>
  
  <p>That code is from official documentation <a href="http://netty.io/4.0/api/io/netty/handler/codec/ReplayingDecoder.html" rel="nofollow">http://netty.io/4.0/api/io/netty/handler/codec/ReplayingDecoder.html</a>  so i really don't understand why it does not work</p>