Program: 106999
Project: 106999
Buggy source:
protected boolean checkPool(ExcludeList avoid,StoragePoolVO pool,DiskProfile dskCh,VMTemplateVO template,List<VMTemplateStoragePoolVO> templatesInPool,StatsCollector sc,DeploymentPlan plan){
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + pool.getName() + "String_Node_Str"+ pool.getId());
  }
  if (avoid.shouldAvoid(pool)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (dskCh.getType().equals(Type.ROOT) && pool.getPoolType().equals(StoragePoolType.Iscsi)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (!pool.getStatus().equals(StoragePoolStatus.Up)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + pool.getStatus().name() + "String_Node_Str");
    }
    return false;
  }
  if (!poolIsCorrectType(dskCh,pool)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  Long clusterId=pool.getClusterId();
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (!(cluster.getHypervisorType() == dskCh.getHypersorType())) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (sc != null) {
    long totalSize=pool.getCapacityBytes();
    StorageStats stats=sc.getStoragePoolStats(pool.getId());
    if (stats == null) {
      stats=sc.getStorageStats(pool.getId());
    }
    if (stats != null) {
      double usedPercentage=((double)stats.getByteUsed() / (double)totalSize);
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ pool.getCapacityBytes()+ "String_Node_Str"+ stats.getByteUsed()+ "String_Node_Str"+ usedPercentage+ "String_Node_Str"+ _storageUsedThreshold);
      }
      if (usedPercentage >= _storageUsedThreshold) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ usedPercentage+ "String_Node_Str"+ _storageUsedThreshold+ "String_Node_Str");
        }
        return false;
      }
    }
  }
  Pair<Long,Long> sizes=_volumeDao.getCountAndTotalByPool(pool.getId());
  long totalAllocatedSize=sizes.second() + sizes.first() * _extraBytesPerVolume;
  boolean tmpinstalled=false;
  List<VMTemplateStoragePoolVO> templatePoolVOs;
  if (templatesInPool != null) {
    templatePoolVOs=templatesInPool;
  }
 else {
    templatePoolVOs=_templatePoolDao.listByPoolId(pool.getId());
  }
  for (  VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
    if ((template != null) && !tmpinstalled && (templatePoolVO.getTemplateId() == template.getId())) {
      tmpinstalled=true;
    }
    long templateSize=templatePoolVO.getTemplateSize();
    totalAllocatedSize+=templateSize + _extraBytesPerVolume;
  }
  if ((template != null) && !tmpinstalled) {
    VMTemplateHostVO templateHostVO=_storageMgr.findVmTemplateHost(template.getId(),plan.getDataCenterId(),plan.getPodId());
    if (templateHostVO == null) {
      s_logger.info("String_Node_Str" + plan.getDataCenterId());
      return false;
    }
 else {
      s_logger.debug("String_Node_Str" + template.getName() + "String_Node_Str"+ 2);
      long templateSize=templateHostVO.getSize();
      long templatePhysicalSize=templateHostVO.getPhysicalSize();
      totalAllocatedSize+=(templateSize + _extraBytesPerVolume) + (templatePhysicalSize + _extraBytesPerVolume);
    }
  }
  long askingSize=dskCh.getSize();
  float storageOverprovisioningFactor=1.0f;
  if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
    storageOverprovisioningFactor=_storageOverprovisioningFactor;
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ (pool.getCapacityBytes() * storageOverprovisioningFactor)+ "String_Node_Str"+ totalAllocatedSize+ "String_Node_Str"+ askingSize);
  }
  if ((pool.getCapacityBytes() * storageOverprovisioningFactor) < (totalAllocatedSize + askingSize)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ (pool.getCapacityBytes() * storageOverprovisioningFactor)+ "String_Node_Str"+ totalAllocatedSize+ "String_Node_Str"+ askingSize);
    }
    return false;
  }
  return true;
}

Fixed version (ground truth):
protected boolean checkPool(ExcludeList avoid,StoragePoolVO pool,DiskProfile dskCh,VMTemplateVO template,List<VMTemplateStoragePoolVO> templatesInPool,StatsCollector sc,DeploymentPlan plan){
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + pool.getName() + "String_Node_Str"+ pool.getId());
  }
  if (avoid.shouldAvoid(pool)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (dskCh.getType().equals(Type.ROOT) && pool.getPoolType().equals(StoragePoolType.Iscsi)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (!pool.getStatus().equals(StoragePoolStatus.Up)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + pool.getStatus().name() + "String_Node_Str");
    }
    return false;
  }
  if (!poolIsCorrectType(dskCh,pool)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  Long clusterId=pool.getClusterId();
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (!(cluster.getHypervisorType() == dskCh.getHypersorType())) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    return false;
  }
  if (sc != null) {
    long totalSize=pool.getCapacityBytes();
    StorageStats stats=sc.getStoragePoolStats(pool.getId());
    if (stats == null) {
      stats=sc.getStorageStats(pool.getId());
    }
    if (stats != null) {
      double usedPercentage=((double)stats.getByteUsed() / (double)totalSize);
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ pool.getCapacityBytes()+ "String_Node_Str"+ stats.getByteUsed()+ "String_Node_Str"+ usedPercentage+ "String_Node_Str"+ _storageUsedThreshold);
      }
      if (usedPercentage >= _storageUsedThreshold) {
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ usedPercentage+ "String_Node_Str"+ _storageUsedThreshold+ "String_Node_Str");
        }
        return false;
      }
    }
  }
  Pair<Long,Long> sizes=_volumeDao.getCountAndTotalByPool(pool.getId());
  long totalAllocatedSize=sizes.second() + sizes.first() * _extraBytesPerVolume;
  boolean tmpinstalled=false;
  List<VMTemplateStoragePoolVO> templatePoolVOs;
  if (templatesInPool != null) {
    templatePoolVOs=templatesInPool;
  }
 else {
    templatePoolVOs=_templatePoolDao.listByPoolId(pool.getId());
  }
  for (  VMTemplateStoragePoolVO templatePoolVO : templatePoolVOs) {
    if ((template != null) && !tmpinstalled && (templatePoolVO.getTemplateId() == template.getId())) {
      tmpinstalled=true;
    }
    long templateSize=templatePoolVO.getTemplateSize();
    totalAllocatedSize+=templateSize + _extraBytesPerVolume;
  }
  if ((template != null) && !tmpinstalled) {
    VMTemplateHostVO templateHostVO=_storageMgr.findVmTemplateHost(template.getId(),pool);
    if (templateHostVO == null) {
      s_logger.info("String_Node_Str" + plan.getDataCenterId());
      return false;
    }
 else {
      s_logger.debug("String_Node_Str" + template.getName() + "String_Node_Str"+ 2);
      long templateSize=templateHostVO.getSize();
      long templatePhysicalSize=templateHostVO.getPhysicalSize();
      totalAllocatedSize+=(templateSize + _extraBytesPerVolume) + (templatePhysicalSize + _extraBytesPerVolume);
    }
  }
  long askingSize=dskCh.getSize();
  float storageOverprovisioningFactor=1.0f;
  if (pool.getPoolType() == StoragePoolType.NetworkFilesystem) {
    storageOverprovisioningFactor=_storageOverprovisioningFactor;
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ (pool.getCapacityBytes() * storageOverprovisioningFactor)+ "String_Node_Str"+ totalAllocatedSize+ "String_Node_Str"+ askingSize);
  }
  if ((pool.getCapacityBytes() * storageOverprovisioningFactor) < (totalAllocatedSize + askingSize)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + pool.getId() + "String_Node_Str"+ (pool.getCapacityBytes() * storageOverprovisioningFactor)+ "String_Node_Str"+ totalAllocatedSize+ "String_Node_Str"+ askingSize);
    }
    return false;
  }
  return true;
}