Program: 12429
Project: 12429
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=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 pbapnsEvent;
  try {
    byte[] bytes=(byte[])msg;
    pbapnsEvent=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",pbapnsEvent);
  }
  if (StringUtils.isEmpty(pbapnsEvent.getUserId()) || pbapnsEvent.getOp() <= 0) {
    logger.error("String_Node_Str");
    ctx.close();
    return;
  }
  if (pbapnsEvent.getTypeId() == PBAPNSEvent.DeviceTypes.Android_VALUE) {
    MetricBuilder.clientAndroidMeter.mark();
  }
 else   if (pbapnsEvent.getTypeId() == PBAPNSEvent.DeviceTypes.iOS_VALUE) {
    MetricBuilder.clientIOSMeter.mark();
  }
  if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.Online_VALUE) {
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    if (null != conn) {
      logger.error("String_Node_Str",pbapnsEvent,conn);
      ack(ctx,conn,pbapnsEvent,MULTI_CLIENTS);
    }
    conn=new Connection(ctx.channel());
    conn.setUserId(pbapnsEvent.getUserId());
    conn.setAppKey(pbapnsEvent.getAppKey());
    ConnectionKeeper.add(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId(),conn);
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(pbapnsEvent));
    ack(ctx,conn,pbapnsEvent,SYNC);
    if (logger.isDebugEnabled()) {
      logger.debug("String_Node_Str",pbapnsEvent);
    }
  }
 else   if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.KeepAlive_VALUE) {
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    ack(ctx,conn,pbapnsEvent,SYNC);
  }
 else   if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.Sleep_VALUE) {
    MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
      @Override public void run(){
        Client c0=ClientServiceImpl.instance.findByUserId(pbapnsEvent.getUserId());
        if (c0 != null) {
          ClientServiceImpl.instance.updateStatus(c0.getId(),2);
        }
      }
    }
);
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    ack(ctx,conn,pbapnsEvent,SYNC);
  }
 else   if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.Awake_VALUE) {
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    if (null == conn) {
      conn=new Connection(ctx.channel());
      conn.setUserId(pbapnsEvent.getUserId());
      conn.setAppKey(pbapnsEvent.getAppKey());
      ConnectionKeeper.add(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId(),conn);
    }
    MessageHandlerPoolTasks.instance.getExecutor().submit(new OnNewlyAddThread(pbapnsEvent));
    ack(ctx,conn,pbapnsEvent,SYNC);
  }
 else   if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.PushAck_VALUE) {
    if (pbapnsEvent.getRead() > 0) {
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          ClientServiceImpl.instance.updateBadge(pbapnsEvent.getUserId(),pbapnsEvent.getRead() * -1);
        }
      }
);
    }
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    ack(ctx,conn,pbapnsEvent,SYNC);
  }
 else   if (pbapnsEvent.getOp() == PBAPNSEvent.Ops.Offline_VALUE) {
    final Connection connection=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    if (connection != null) {
      ConnectionKeeper.remove(connection.getAppKey(),connection.getUserId());
      connection.close();
      logger.info("String_Node_Str",pbapnsEvent);
      MessageHandlerPoolTasks.instance.getExecutor().submit(new Runnable(){
        @Override public void run(){
          Client c0=ClientServiceImpl.instance.findByUserId(pbapnsEvent.getUserId());
          if (c0 != null) {
            ClientServiceImpl.instance.updateOfflineTs(c0.getId(),connection.getLastOpTime());
          }
        }
      }
);
    }
    ctx.close();
  }
}