Program: 12418
Project: 12418
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 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) {
    boolean newDevice=false;
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    if (null != conn) {
      if (!conn.getToken().equalsIgnoreCase(pbapnsEvent.getToken())) {
        newDevice=true;
        logger.error("String_Node_Str",pbapnsEvent,conn);
        ack(ctx,conn,pbapnsEvent,MULTI_CLIENTS);
      }
    }
    if (newDevice) {
      conn=new Connection(ctx);
      conn.setUserId(pbapnsEvent.getUserId());
      conn.setAppKey(pbapnsEvent.getAppKey());
      conn.setToken(pbapnsEvent.getToken());
      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);
      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();
  }
}

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) {
    boolean newConnection=true;
    Connection conn=ConnectionKeeper.get(pbapnsEvent.getAppKey(),pbapnsEvent.getUserId());
    if (null != conn) {
      if (!conn.getToken().equalsIgnoreCase(pbapnsEvent.getToken())) {
        newConnection=true;
        logger.error("String_Node_Str",pbapnsEvent,conn);
        ack(ctx,conn,pbapnsEvent,MULTI_CLIENTS);
      }
 else {
        newConnection=false;
      }
    }
    if (newConnection) {
      conn=new Connection(ctx);
      conn.setUserId(pbapnsEvent.getUserId());
      conn.setAppKey(pbapnsEvent.getAppKey());
      conn.setToken(pbapnsEvent.getToken());
      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);
      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();
  }
}