Program: 156088
Project: 156088
Buggy source:
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.skipBytes(2);
  buf.readUnsignedShort();
  int version=buf.readUnsignedByte();
  ChannelBuffer id=buf.readBytes(20);
  int type=ChannelBuffers.swapShort(buf.readShort());
  if (!identify(id.toString(Charset.defaultCharset()).trim(),channel,remoteAddress)) {
    return null;
  }
  if (version == 4) {
    if (type == MSG_SC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_SC_HEARTBEAT_RESPONSE,null);
    }
 else     if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) {
      if (type == MSG_SC_LOGIN) {
        ChannelBuffer response=ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN,10);
        response.writeInt(0xFFFFFFFF);
        response.writeShort(0);
        response.writeInt((int)(System.currentTimeMillis() / 1000));
        sendResponse(channel,remoteAddress,version,id,MSG_SC_LOGIN_RESPONSE,response);
      }
      if (type == MSG_SC_GPS) {
        buf.readUnsignedByte();
      }
 else       if (type == MSG_SC_ALARM) {
        buf.readUnsignedInt();
      }
 else       if (type == MSG_SC_CURRENT_LOCATION) {
        buf.readUnsignedShort();
      }
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      long odometer=buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedShort();
      long status=buf.readUnsignedInt();
      buf.skipBytes(8);
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_ODOMETER,odometer);
        position.set(Event.KEY_STATUS,status);
        positions.add(position);
      }
      if (!positions.isEmpty()) {
        return positions;
      }
    }
 else     if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) {
      return readPosition(buf);
    }
  }
 else {
    if (type == MSG_CC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_HEARTBEAT_RESPONSE,null);
      buf.readUnsignedByte();
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_STATUS,buf.readUnsignedInt());
        position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Event.KEY_LAC,buf.readUnsignedShort());
        position.set(Event.KEY_CELL,buf.readUnsignedShort());
        positions.add(position);
        return positions;
      }
    }
 else     if (type == MSG_CC_LOGIN) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_LOGIN_RESPONSE,null);
      Position position=readPosition(buf);
      position.set(Event.KEY_STATUS,buf.readUnsignedInt());
      position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      return position;
    }
  }
  return null;
}

Fixed version (ground truth):
@Override protected Object decode(Channel channel,SocketAddress remoteAddress,Object msg) throws Exception {
  ChannelBuffer buf=(ChannelBuffer)msg;
  buf.skipBytes(2);
  buf.readUnsignedShort();
  int version=buf.readUnsignedByte();
  ChannelBuffer id=buf.readBytes(20);
  int type=ChannelBuffers.swapShort(buf.readShort());
  if (!identify(id.toString(Charset.defaultCharset()).trim(),channel,remoteAddress)) {
    return null;
  }
  if (version == 4) {
    if (type == MSG_SC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_SC_HEARTBEAT_RESPONSE,null);
    }
 else     if (type == MSG_SC_LOGIN || type == MSG_SC_LOGOUT || type == MSG_SC_GPS || type == MSG_SC_ALARM || type == MSG_SC_CURRENT_LOCATION) {
      if (type == MSG_SC_LOGIN) {
        ChannelBuffer response=ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN,10);
        response.writeInt(0xFFFFFFFF);
        response.writeShort(0);
        response.writeInt((int)(System.currentTimeMillis() / 1000));
        sendResponse(channel,remoteAddress,version,id,MSG_SC_LOGIN_RESPONSE,response);
      }
      if (type == MSG_SC_GPS) {
        buf.readUnsignedByte();
      }
 else       if (type == MSG_SC_ALARM) {
        buf.readUnsignedInt();
      }
 else       if (type == MSG_SC_CURRENT_LOCATION) {
        buf.readUnsignedShort();
      }
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      long odometer=buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedInt();
      buf.readUnsignedShort();
      long status=buf.readUnsignedInt();
      buf.skipBytes(8);
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_ODOMETER,odometer);
        position.set(Event.KEY_STATUS,status);
        positions.add(position);
      }
      if (!positions.isEmpty()) {
        return positions;
      }
    }
 else     if (type == MSG_SC_GPS_SLEEP || type == MSG_SC_AGPS_REQUEST) {
      return readPosition(buf);
    }
  }
 else {
    if (type == MSG_CC_HEARTBEAT) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_HEARTBEAT_RESPONSE,null);
      buf.readUnsignedByte();
      int count=buf.readUnsignedByte();
      List<Position> positions=new LinkedList<>();
      for (int i=0; i < count; i++) {
        Position position=readPosition(buf);
        position.set(Event.KEY_STATUS,buf.readUnsignedInt());
        position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
        position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        buf.readUnsignedByte();
        position.set(Event.KEY_LAC,buf.readUnsignedShort());
        position.set(Event.KEY_CELL,buf.readUnsignedShort());
        positions.add(position);
      }
      return positions;
    }
 else     if (type == MSG_CC_LOGIN) {
      sendResponse(channel,remoteAddress,version,id,MSG_CC_LOGIN_RESPONSE,null);
      Position position=readPosition(buf);
      position.set(Event.KEY_STATUS,buf.readUnsignedInt());
      position.set(Event.KEY_BATTERY,buf.readUnsignedByte());
      position.set(Event.KEY_ODOMETER,buf.readUnsignedInt());
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      buf.readUnsignedByte();
      return position;
    }
  }
  return null;
}