Program: 106462
Project: 106462
Buggy source:
protected List<Host> allocateTo(DeploymentPlan plan,ServiceOffering offering,VMTemplateVO template,ExcludeList avoid,List<HostVO> hosts,int returnUpTo,boolean considerReservedCapacity,Account account){
  if (_allocationAlgorithm.equals("String_Node_Str") || _allocationAlgorithm.equals("String_Node_Str")) {
    Collections.shuffle(hosts);
  }
 else   if (_allocationAlgorithm.equals("String_Node_Str")) {
    hosts=reorderHostsByNumberOfVms(plan,hosts,account);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str"+ hosts);
  }
  hosts=prioritizeHosts(template,hosts);
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str"+ hosts);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + (offering.getCpu() * offering.getSpeed()) + "String_Node_Str"+ offering.getRamSize());
  }
  List<Host> suitableHosts=new ArrayList<Host>();
  for (  HostVO host : hosts) {
    if (suitableHosts.size() == returnUpTo) {
      break;
    }
    if (avoid.shouldAvoid(host)) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getName() + "String_Node_Str"+ host.getId()+ "String_Node_Str");
      }
      continue;
    }
    Long vmCount=_vmInstanceDao.countRunningByHostId(host.getId());
    Long maxGuestLimit=getHostMaxGuestLimit(host);
    if (vmCount.longValue() == maxGuestLimit.longValue()) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getName() + "String_Node_Str"+ host.getId()+ "String_Node_Str"+ maxGuestLimit+ "String_Node_Str");
      }
      continue;
    }
    boolean numCpusGood=host.getCpus().intValue() >= offering.getCpu();
    boolean cpuFreqGood=host.getSpeed().intValue() >= offering.getSpeed();
    int cpu_requested=offering.getCpu() * offering.getSpeed();
    long ram_requested=offering.getRamSize() * 1024L * 1024L;
    boolean hostHasCapacity=_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,false,_factor,considerReservedCapacity);
    if (numCpusGood && cpuFreqGood && hostHasCapacity) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getId());
      }
      suitableHosts.add(host);
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ numCpusGood+ "String_Node_Str"+ cpuFreqGood+ "String_Node_Str"+ hostHasCapacity);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + suitableHosts.size() + "String_Node_Str");
  }
  return suitableHosts;
}

Fixed version (ground truth):
protected List<Host> allocateTo(DeploymentPlan plan,ServiceOffering offering,VMTemplateVO template,ExcludeList avoid,List<HostVO> hosts,int returnUpTo,boolean considerReservedCapacity,Account account){
  if (_allocationAlgorithm.equals("String_Node_Str") || _allocationAlgorithm.equals("String_Node_Str")) {
    Collections.shuffle(hosts);
  }
 else   if (_allocationAlgorithm.equals("String_Node_Str")) {
    hosts=reorderHostsByNumberOfVms(plan,hosts,account);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str"+ hosts);
  }
  hosts=prioritizeHosts(template,hosts);
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + hosts.size() + "String_Node_Str"+ hosts);
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + (offering.getCpu() * offering.getSpeed()) + "String_Node_Str"+ offering.getRamSize());
  }
  List<Host> suitableHosts=new ArrayList<Host>();
  for (  HostVO host : hosts) {
    if (suitableHosts.size() == returnUpTo) {
      break;
    }
    if (avoid.shouldAvoid(host)) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getName() + "String_Node_Str"+ host.getId()+ "String_Node_Str");
      }
      continue;
    }
    if (_capacityMgr.checkIfHostReachMaxGuestLimit(host)) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getName() + "String_Node_Str"+ host.getId()+ "String_Node_Str");
      }
      continue;
    }
    boolean numCpusGood=host.getCpus().intValue() >= offering.getCpu();
    boolean cpuFreqGood=host.getSpeed().intValue() >= offering.getSpeed();
    int cpu_requested=offering.getCpu() * offering.getSpeed();
    long ram_requested=offering.getRamSize() * 1024L * 1024L;
    boolean hostHasCapacity=_capacityMgr.checkIfHostHasCapacity(host.getId(),cpu_requested,ram_requested,false,_factor,considerReservedCapacity);
    if (numCpusGood && cpuFreqGood && hostHasCapacity) {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getId());
      }
      suitableHosts.add(host);
    }
 else {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ numCpusGood+ "String_Node_Str"+ cpuFreqGood+ "String_Node_Str"+ hostHasCapacity);
      }
    }
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + suitableHosts.size() + "String_Node_Str");
  }
  return suitableHosts;
}