Program: 12421
Project: 12421
Buggy source:
/** 
 * 读取新消息 LengthFieldBasedFrameDecoder 自动解包
 */
@Override public void channelRead(ChannelHandlerContext ctx,Object msg){
  if (logger.isDebugEnabled()) {
    logger.info("String_Node_Str",ctx.channel().hashCode());
  }
  MetricBuilder.requestMeter.mark();
  final PBAPNSEvent cc;
  try {
    byte[] bytes=(byte[])msg;
    cc=PBAPNSEvent.newBuilder().mergeFrom(bytes).build();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    ctx.close();
    return;
  }
  ReferenceCountUtil.release(msg);
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str",cc);
  }
  if (StringUtils.isEmpty(cc.getUserId()) || cc.getOp() <= 0) {
    logger.error("String_Node_Str");
    ctx.close();
    return;
  }
  if (cc.getTypeId() == PBAPNSEvent.DeviceTypes.Android_VALUE) {
    MetricBuilder.clientAndroidMeter.mark();
  }
 else   if (cc.getTypeId() == PBAPNSEvent.DeviceTypes.iOS_VALUE) {
    MetricBuilder.clientIOSMeter.mark();
  }
  if (cc.getOp() == PBAPNSEvent.Ops.Online_VALUE) {
    Connection conn=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (null != conn) {
      logger.error("String_Node_Str",cc,conn);
      ack(ctx,cc,MULTI_CLIENTS);
      conn.close();
    }
    conn=new Connection(ctx.channel());
    conn.setUserId(cc.getUserId());
    conn.setAppKey(cc.getAppKey());
    ConnectionKeeper.add(cc.getAppKey(),cc.getUserId(),conn);
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(cc));
    ack(ctx,cc,SYNC);
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str",cc);
    }
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.KeepAlive_VALUE) {
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Sleep_VALUE) {
    MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
      @Override public void run(){
        Client c0=ClientServiceImpl.instance.findByUserId(cc.getUserId());
        if (c0 != null) {
          ClientServiceImpl.instance.updateStatus(c0.getId(),2);
        }
      }
    }
);
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Awake_VALUE) {
    Connection conn=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (null == conn) {
      conn=new Connection(ctx.channel());
      conn.setUserId(cc.getUserId());
      conn.setAppKey(cc.getAppKey());
      ConnectionKeeper.add(cc.getAppKey(),cc.getUserId(),conn);
    }
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(cc));
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.PushAck_VALUE) {
    if (cc.getRead() > 0) {
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          ClientServiceImpl.instance.updateBadge(cc.getUserId(),cc.getRead() * -1);
        }
      }
);
    }
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Offline_VALUE) {
    final Connection connection=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (connection != null) {
      ConnectionKeeper.remove(connection.getAppKey(),connection.getUserId());
      connection.close();
      logger.info("String_Node_Str",cc);
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          Client c0=ClientServiceImpl.instance.findByUserId(cc.getUserId());
          if (c0 != null) {
            ClientServiceImpl.instance.updateOfflineTs(c0.getId(),connection.getLastOpTime());
          }
        }
      }
);
    }
    ctx.close();
  }
}

Fixed version (ground truth):
/** 
 * 读取新消息 LengthFieldBasedFrameDecoder 自动解包
 */
@Override public void channelRead(ChannelHandlerContext ctx,Object msg){
  if (logger.isDebugEnabled()) {
    logger.info("String_Node_Str",ctx.channel().hashCode());
  }
  MetricBuilder.requestMeter.mark();
  final PBAPNSEvent cc;
  try {
    byte[] bytes=(byte[])msg;
    cc=PBAPNSEvent.newBuilder().mergeFrom(bytes).build();
  }
 catch (  Exception e) {
    logger.error("String_Node_Str",e);
    ctx.close();
    return;
  }
  ReferenceCountUtil.release(msg);
  if (logger.isDebugEnabled()) {
    logger.debug("String_Node_Str",cc);
  }
  if (StringUtils.isEmpty(cc.getUserId()) || cc.getOp() <= 0) {
    logger.error("String_Node_Str");
    ctx.close();
    return;
  }
  if (cc.getTypeId() == PBAPNSEvent.DeviceTypes.Android_VALUE) {
    MetricBuilder.clientAndroidMeter.mark();
  }
 else   if (cc.getTypeId() == PBAPNSEvent.DeviceTypes.iOS_VALUE) {
    MetricBuilder.clientIOSMeter.mark();
  }
  if (cc.getOp() == PBAPNSEvent.Ops.Online_VALUE) {
    Connection conn=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (null != conn) {
      logger.error("String_Node_Str",cc,conn);
      ack(ctx,cc,MULTI_CLIENTS);
    }
    conn=new Connection(ctx.channel());
    conn.setUserId(cc.getUserId());
    conn.setAppKey(cc.getAppKey());
    ConnectionKeeper.add(cc.getAppKey(),cc.getUserId(),conn);
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(cc));
    ack(ctx,cc,SYNC);
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str",cc);
    }
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.KeepAlive_VALUE) {
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Sleep_VALUE) {
    MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
      @Override public void run(){
        Client c0=ClientServiceImpl.instance.findByUserId(cc.getUserId());
        if (c0 != null) {
          ClientServiceImpl.instance.updateStatus(c0.getId(),2);
        }
      }
    }
);
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Awake_VALUE) {
    Connection conn=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (null == conn) {
      conn=new Connection(ctx.channel());
      conn.setUserId(cc.getUserId());
      conn.setAppKey(cc.getAppKey());
      ConnectionKeeper.add(cc.getAppKey(),cc.getUserId(),conn);
    }
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(cc));
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.PushAck_VALUE) {
    if (cc.getRead() > 0) {
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          ClientServiceImpl.instance.updateBadge(cc.getUserId(),cc.getRead() * -1);
        }
      }
);
    }
    ack(ctx,cc,SYNC);
  }
 else   if (cc.getOp() == PBAPNSEvent.Ops.Offline_VALUE) {
    final Connection connection=ConnectionKeeper.get(cc.getAppKey(),cc.getUserId());
    if (connection != null) {
      ConnectionKeeper.remove(connection.getAppKey(),connection.getUserId());
      connection.close();
      logger.info("String_Node_Str",cc);
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          Client c0=ClientServiceImpl.instance.findByUserId(cc.getUserId());
          if (c0 != null) {
            ClientServiceImpl.instance.updateOfflineTs(c0.getId(),connection.getLastOpTime());
          }
        }
      }
);
    }
    ctx.close();
  }
}