Program: 49080
Project: 49080
Buggy source:
private boolean validateRacksInfo(ClusterCreate cluster,List<String> failedMsgList){
  boolean valid=true;
  Map<String,NodeGroupCreate> allGroups=new TreeMap<String,NodeGroupCreate>();
  if (cluster.getNodeGroups() == null) {
    return valid;
  }
  List<RackInfo> racksInfo=rackInfoMgr.exportRackInfo();
  if ((cluster.getTopologyPolicy() == TopologyType.HVE || cluster.getTopologyPolicy() == TopologyType.RACK_AS_RACK) && racksInfo.isEmpty()) {
    valid=false;
    throw ClusterConfigException.TOPOLOGY_WITH_NO_MAPPING_INFO_EXIST(cluster.getTopologyPolicy().toString());
  }
  for (  NodeGroupCreate nodeGroupCreate : cluster.getNodeGroups()) {
    allGroups.put(nodeGroupCreate.getName(),nodeGroupCreate);
  }
  for (  NodeGroupCreate ngc : cluster.getNodeGroups()) {
    PlacementPolicy policies=ngc.getPlacementPolicies();
    if (policies != null && policies.getGroupAssociations() != null) {
      continue;
    }
    if (ngc.getStorage() != null && ngc.getStorage().getType() != null && ngc.getStorage().getType().equals(DatastoreType.SHARED.toString())) {
      continue;
    }
    if (policies != null && policies.getGroupRacks() != null) {
      if (racksInfo.isEmpty()) {
        valid=false;
        throw ClusterConfigException.RACKPOLICY_WITH_NO_MAPPING_INFO_EXIST(ngc.getName());
      }
      GroupRacks r=policies.getGroupRacks();
      GroupRacksType rackType=r.getType();
      Set<String> specifiedRacks=new HashSet<String>(Arrays.asList(r.getRacks()));
      List<String> intersecRacks=new ArrayList<String>();
      int intersecHostNum=0;
      int maxIntersecHostNum=0;
      for (      RackInfo rackInfo : racksInfo) {
        if (specifiedRacks.isEmpty() || specifiedRacks.size() == 0 || specifiedRacks.contains(rackInfo.getName())) {
          intersecHostNum+=rackInfo.getHosts().size();
          intersecRacks.add(rackInfo.getName());
          if (rackInfo.getHosts().size() > maxIntersecHostNum) {
            maxIntersecHostNum=rackInfo.getHosts().size();
          }
        }
      }
      if (intersecRacks.size() == 0) {
        valid=false;
        throw ClusterConfigException.NO_VALID_RACK(ngc.getName());
      }
      if (ngc.calculateHostNum() != null) {
        if (rackType.equals(GroupRacksType.ROUNDROBIN) && ngc.calculateHostNum() > intersecHostNum) {
          valid=false;
          throw ClusterConfigException.LACK_PHYSICAL_HOSTS(ngc.getName(),ngc.calculateHostNum(),intersecHostNum);
        }
 else         if (rackType.equals(GroupRacksType.SAMERACK) && ngc.calculateHostNum() > maxIntersecHostNum) {
          valid=false;
          throw ClusterConfigException.LACK_PHYSICAL_HOSTS(ngc.getName(),ngc.calculateHostNum(),maxIntersecHostNum);
        }
      }
      r.setRacks(intersecRacks.toArray(new String[intersecRacks.size()]));
    }
  }
  return valid;
}

Fixed version (ground truth):
private boolean validateRacksInfo(ClusterCreate cluster,List<String> failedMsgList){
  boolean valid=true;
  Map<String,NodeGroupCreate> allGroups=new TreeMap<String,NodeGroupCreate>();
  if (cluster.getNodeGroups() == null) {
    return valid;
  }
  List<RackInfo> racksInfo=rackInfoMgr.exportRackInfo();
  if ((cluster.getTopologyPolicy() == TopologyType.HVE || cluster.getTopologyPolicy() == TopologyType.RACK_AS_RACK) && racksInfo.isEmpty()) {
    valid=false;
    throw ClusterConfigException.TOPOLOGY_WITH_NO_MAPPING_INFO_EXIST(cluster.getTopologyPolicy().toString());
  }
  for (  NodeGroupCreate nodeGroupCreate : cluster.getNodeGroups()) {
    allGroups.put(nodeGroupCreate.getName(),nodeGroupCreate);
  }
  for (  NodeGroupCreate ngc : cluster.getNodeGroups()) {
    PlacementPolicy policies=ngc.getPlacementPolicies();
    if (policies != null && policies.getGroupAssociations() != null) {
      continue;
    }
    if (ngc.getStorage() != null && ngc.getStorage().getType() != null && ngc.getStorage().getType().equals(DatastoreType.SHARED.toString())) {
      continue;
    }
    if (policies != null && policies.getGroupRacks() != null) {
      if (racksInfo.isEmpty()) {
        valid=false;
        throw ClusterConfigException.RACKPOLICY_WITH_NO_MAPPING_INFO_EXIST(ngc.getName());
      }
      GroupRacks r=policies.getGroupRacks();
      GroupRacksType rackType=r.getType();
      Set<String> specifiedRacks=new HashSet<String>(Arrays.asList(r.getRacks()));
      List<String> intersecRacks=new ArrayList<String>();
      int intersecHostNum=0;
      int maxIntersecHostNum=0;
      for (      RackInfo rackInfo : racksInfo) {
        if (specifiedRacks.isEmpty() || specifiedRacks.size() == 0 || specifiedRacks.contains(rackInfo.getName())) {
          intersecHostNum+=rackInfo.getHosts().size();
          intersecRacks.add(rackInfo.getName());
          if (rackInfo.getHosts().size() > maxIntersecHostNum) {
            maxIntersecHostNum=rackInfo.getHosts().size();
          }
        }
      }
      if (intersecRacks.size() == 0) {
        valid=false;
        throw ClusterConfigException.NO_VALID_RACK(ngc.getName());
      }
      if (ngc.calculateHostNum() != null) {
        if (rackType.equals(GroupRacksType.ROUNDROBIN) && ngc.calculateHostNum() > intersecHostNum) {
          valid=false;
          throw ClusterConfigException.LACK_PHYSICAL_HOSTS(ngc.getName(),ngc.calculateHostNum(),intersecHostNum);
        }
 else         if (rackType.equals(GroupRacksType.SAMERACK) && ngc.calculateHostNum() > maxIntersecHostNum) {
          valid=false;
          throw ClusterConfigException.LACK_PHYSICAL_HOSTS(ngc.getName(),ngc.calculateHostNum(),maxIntersecHostNum);
        }
      }
      if (specifiedRacks.isEmpty()) {
        r.setRacks(new String[0]);
      }
 else {
        r.setRacks(intersecRacks.toArray(new String[intersecRacks.size()]));
      }
    }
  }
  return valid;
}