Program: 107132
Project: 107132
Buggy source:
protected boolean checkPool(ExcludeList avoid,StoragePoolVO pool,DiskProfile dskCh,VMTemplateVO template,List<VMTemplateStoragePoolVO> templatesInPool,StatsCollector sc){
  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(VolumeType.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.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) {
        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) {
    HostVO secondaryStorageHost=_storageMgr.getSecondaryStorageHost(pool.getDataCenterId());
    if (secondaryStorageHost == null) {
      return false;
    }
 else {
      VMTemplateHostVO templateHostVO=_templateHostDao.findByHostTemplate(secondaryStorageHost.getId(),template.getId());
      if (templateHostVO == null) {
        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();
  int storageOverprovisioningFactor=1;
  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){
  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(VolumeType.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) {
        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) {
    HostVO secondaryStorageHost=_storageMgr.getSecondaryStorageHost(pool.getDataCenterId());
    if (secondaryStorageHost == null) {
      return false;
    }
 else {
      VMTemplateHostVO templateHostVO=_templateHostDao.findByHostTemplate(secondaryStorageHost.getId(),template.getId());
      if (templateHostVO == null) {
        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();
  int storageOverprovisioningFactor=1;
  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;
}