Program: 49022
Project: 49022
Buggy source:
@Transactional(propagation=Propagation.MANDATORY) public static void hasEnoughHost(IRackDAO rackDao,NodeGroupEntity nodeGroup,int instanceNum){
  if (nodeGroup.getInstancePerHost() != null) {
    int requiredHostNum=instanceNum / nodeGroup.getInstancePerHost();
    if (nodeGroup.getGroupRacks() != null) {
      GroupRacks groupRacks=new Gson().fromJson(nodeGroup.getGroupRacks(),GroupRacks.class);
      GroupRacksType rackType=groupRacks.getType();
      List<RackInfo> racksInfo=new ArrayList<RackInfo>();
      List<RackEntity> racks=rackDao.findAll();
      for (      RackEntity rack : racks) {
        List<PhysicalHostEntity> hostEntities=rack.getHosts();
        if (hostEntities != null && !hostEntities.isEmpty()) {
          List<String> hosts=new ArrayList<String>(hostEntities.size());
          for (          PhysicalHostEntity he : hostEntities) {
            hosts.add(he.getName());
          }
          RackInfo rackInfo=new RackInfo();
          rackInfo.setName(rack.getName());
          rackInfo.setHosts(hosts);
          racksInfo.add(rackInfo);
        }
      }
      Set<String> specifiedRacks=new HashSet<String>(Arrays.asList(groupRacks.getRacks()));
      List<String> IntersecRacks=new ArrayList<String>();
      Integer IntersecHostNum=0;
      Integer 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 (rackType.equals(GroupRacksType.ROUNDROBIN) && IntersecHostNum < requiredHostNum) {
        throw ClusterConfigException.LACK_PHYSICAL_HOSTS(nodeGroup.getName(),requiredHostNum,IntersecHostNum);
      }
 else       if (rackType.equals(GroupRacksType.SAMERACK) && requiredHostNum > maxIntersecHostNum) {
        throw ClusterConfigException.LACK_PHYSICAL_HOSTS(nodeGroup.getName(),requiredHostNum,maxIntersecHostNum);
      }
      if (specifiedRacks.isEmpty()) {
        groupRacks.setRacks(new String[0]);
      }
 else {
        groupRacks.setRacks(IntersecRacks.toArray(new String[IntersecRacks.size()]));
      }
      nodeGroup.setGroupRacks((new Gson()).toJson(groupRacks));
    }
  }
}

Fixed version (ground truth):
public static void hasEnoughHost(RackInfoManager rackInfoMgr,ClusterEntityManager clusterEntityMgr,NodeGroupEntity nodeGroup,int instanceNum){
  if (nodeGroup.getInstancePerHost() != null) {
    int requiredHostNum=instanceNum / nodeGroup.getInstancePerHost();
    if (nodeGroup.getGroupRacks() != null) {
      GroupRacks groupRacks=new Gson().fromJson(nodeGroup.getGroupRacks(),GroupRacks.class);
      GroupRacksType rackType=groupRacks.getType();
      List<RackInfo> racksInfo=rackInfoMgr.getRackInfos();
      Set<String> specifiedRacks=new HashSet<String>(Arrays.asList(groupRacks.getRacks()));
      List<String> IntersecRacks=new ArrayList<String>();
      Integer IntersecHostNum=0;
      Integer 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 (rackType.equals(GroupRacksType.ROUNDROBIN) && IntersecHostNum < requiredHostNum) {
        throw ClusterConfigException.LACK_PHYSICAL_HOSTS(nodeGroup.getName(),requiredHostNum,IntersecHostNum);
      }
 else       if (rackType.equals(GroupRacksType.SAMERACK) && requiredHostNum > maxIntersecHostNum) {
        throw ClusterConfigException.LACK_PHYSICAL_HOSTS(nodeGroup.getName(),requiredHostNum,maxIntersecHostNum);
      }
      if (specifiedRacks.isEmpty()) {
        groupRacks.setRacks(new String[0]);
      }
 else {
        groupRacks.setRacks(IntersecRacks.toArray(new String[IntersecRacks.size()]));
      }
      nodeGroup.setGroupRacks((new Gson()).toJson(groupRacks));
      clusterEntityMgr.update(nodeGroup);
    }
  }
}