title: Netty 4.0.0.CR3 - LengthFieldBasedFrameDecoder maxFrameLength Exceeds Integer.MAX_VALUE
body: <p>So far I have been amp'd about upgrading from Netty version 3.5.7.Final to 4.0.0CR3 until I ran into my final problem during the upgrade.... the LengthFieldBasedFrameDecoder. Each available constructor requires a maxFrameLength which I set to Integer.MAX_VALUE but when running the client/server I get several stack traces (one shown below) that state that the Integer.MAX_VALUE has been exceeded (2147483647). I have tried to take a shot at configuring the maximum channel buffer size by digging through the ChannelConfig class in the API docs and various other stackoverflow post, still to no prevail. Does anyone know if there is a missing option I can set or a way to prevent the reads from even being this high?</p>
  
  <p>Stack Trace:</p>
  
  <pre><code>io.netty.handler.codec.TooLongFrameException: Adjusted frame length exceeds 2147483647: 4156555235 - discarded
  at io.netty.handler.codec.LengthFieldBasedFrameDecoder.fail(LengthFieldBasedFrameDecoder.java:486)
  at io.netty.handler.codec.LengthFieldBasedFrameDecoder.failIfNecessary(LengthFieldBasedFrameDecoder.java:462)
  at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:397)
  at io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:352)
  at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:111)
  at io.netty.handler.codec.ByteToMessageDecoder.inboundBufferUpdated(ByteToMessageDecoder.java:69)
  at io.netty.channel.ChannelInboundByteHandlerAdapter.inboundBufferUpdated(ChannelInboundByteHandlerAdapter.java:46)
  at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:1031)
  at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:998)
  at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:978)
  at io.netty.handler.timeout.IdleStateHandler.inboundBufferUpdated(IdleStateHandler.java:257)
  at io.netty.channel.DefaultChannelHandlerContext.invokeInboundBufferUpdated(DefaultChannelHandlerContext.java:1057)
  at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated0(DefaultChannelHandlerContext.java:998)
  at io.netty.channel.DefaultChannelHandlerContext.fireInboundBufferUpdated(DefaultChannelHandlerContext.java:978)
  at io.netty.channel.DefaultChannelPipeline.fireInboundBufferUpdated(DefaultChannelPipeline.java:828)
  at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:118)
  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:429)
  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:392)
  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:322)
  at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:114)
  at java.lang.Thread.run(Thread.java:680)
  </code></pre>
  
  <p>My Client is configured as followed:</p>
  
  <pre><code>peerClient.bootstrap = new Bootstrap();
  
  peerClient.bootstrap.group(new NioEventLoopGroup())
            .channel(NioSocketChannel.class)
            .option(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT)
            .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 120000)
            .option(ChannelOption.SO_KEEPALIVE, true)
            .option(ChannelOption.TCP_NODELAY, true)
            .option(ChannelOption.SO_REUSEADDR, true)
            .handler(PeerInitializer.newInstance());
  </code></pre>
  
  <p>My Server Configuration:</p>
  
  <pre><code>result.serverBootstrap = new ServerBootstrap();
  
  result.serverBootstrap.group(new NioEventLoopGroup(), new NioEventLoopGroup())
        .channel(NioServerSocketChannel.class)
        .handler(new LoggingHandler(LogLevel.INFO))
        .childHandler(PeerInitializer.newInstance())
        .childOption(ChannelOption.ALLOCATOR, UnpooledByteBufAllocator.DEFAULT);
  </code></pre>
  
  <p>The initChannel method overridden with a custom class extending ChannelInitializer</p>
  
  <pre><code>public class PeerInitializer extends ChannelInitializer&lt;SocketChannel&gt;
  
  @Override
  protected void initChannel(SocketChannel ch) throws Exception {
      final ChannelPipeline pipeline = ch.pipeline();
  
      pipeline.addLast(
              messageEncoder,
              HandshakeDecoder.newInstance(),
              connectionHandler,
              handshakeHandler,
              new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4),
              messageHandler);
  }
  </code></pre>