Program: 106092
Project: 106092
Buggy source:
@Override public void collectVmDiskStatistics(final UserVmVO userVm){
  if (!userVm.getHypervisorType().equals(HypervisorType.KVM))   return;
  s_logger.debug("String_Node_Str");
  long hostId=userVm.getHostId();
  List<String> vmNames=new ArrayList<String>();
  vmNames.add(userVm.getInstanceName());
  final HostVO host=_hostDao.findById(hostId);
  GetVmDiskStatsAnswer diskStatsAnswer=null;
  try {
    diskStatsAnswer=(GetVmDiskStatsAnswer)_agentMgr.easySend(hostId,new GetVmDiskStatsCommand(vmNames,host.getGuid(),host.getName()));
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str" + userVm.getHostName() + "String_Node_Str"+ host.getName(),e);
    return;
  }
  if (diskStatsAnswer != null) {
    if (!diskStatsAnswer.getResult()) {
      s_logger.warn("String_Node_Str" + userVm.getHostName() + "String_Node_Str"+ host.getName()+ "String_Node_Str"+ diskStatsAnswer.getDetails());
      return;
    }
    try {
      final GetVmDiskStatsAnswer diskStatsAnswerFinal=diskStatsAnswer;
      Transaction.execute(new TransactionCallbackNoReturn(){
        @Override public void doInTransactionWithoutResult(        TransactionStatus status){
          HashMap<String,List<VmDiskStatsEntry>> vmDiskStatsByName=diskStatsAnswerFinal.getVmDiskStatsMap();
          if (vmDiskStatsByName == null)           return;
          List<VmDiskStatsEntry> vmDiskStats=vmDiskStatsByName.get(userVm.getInstanceName());
          if (vmDiskStats == null)           return;
          for (          VmDiskStatsEntry vmDiskStat : vmDiskStats) {
            SearchCriteria<VolumeVO> sc_volume=_volsDao.createSearchCriteria();
            sc_volume.addAnd("String_Node_Str",SearchCriteria.Op.EQ,vmDiskStat.getPath());
            VolumeVO volume=_volsDao.search(sc_volume,null).get(0);
            VmDiskStatisticsVO previousVmDiskStats=_vmDiskStatsDao.findBy(userVm.getAccountId(),userVm.getDataCenterId(),userVm.getId(),volume.getId());
            VmDiskStatisticsVO vmDiskStat_lock=_vmDiskStatsDao.lock(userVm.getAccountId(),userVm.getDataCenterId(),userVm.getId(),volume.getId());
            if ((vmDiskStat.getIORead() == 0) && (vmDiskStat.getIOWrite() == 0) && (vmDiskStat.getBytesRead() == 0)&& (vmDiskStat.getBytesWrite() == 0)) {
              s_logger.debug("String_Node_Str");
              continue;
            }
            if (vmDiskStat_lock == null) {
              s_logger.warn("String_Node_Str" + userVm.getAccountId() + "String_Node_Str"+ userVm.getId()+ "String_Node_Str"+ volume.getId());
              continue;
            }
            if (previousVmDiskStats != null && ((previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead()) || ((previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock.getCurrentIOWrite()) || (previousVmDiskStats.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats.getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite())))) {
              s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat.getIOWrite()+ "String_Node_Str"+ vmDiskStat.getBytesRead()+ "String_Node_Str"+ vmDiskStat.getBytesWrite());
              continue;
            }
            if (vmDiskStat_lock.getCurrentIORead() > vmDiskStat.getIORead()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentIORead());
              }
              vmDiskStat_lock.setNetIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
            }
            vmDiskStat_lock.setCurrentIORead(vmDiskStat.getIORead());
            if (vmDiskStat_lock.getCurrentIOWrite() > vmDiskStat.getIOWrite()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIOWrite()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentIOWrite());
              }
              vmDiskStat_lock.setNetIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
            }
            vmDiskStat_lock.setCurrentIOWrite(vmDiskStat.getIOWrite());
            if (vmDiskStat_lock.getCurrentBytesRead() > vmDiskStat.getBytesRead()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getBytesRead()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentBytesRead());
              }
              vmDiskStat_lock.setNetBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
            }
            vmDiskStat_lock.setCurrentBytesRead(vmDiskStat.getBytesRead());
            if (vmDiskStat_lock.getCurrentBytesWrite() > vmDiskStat.getBytesWrite()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getBytesWrite()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentBytesWrite());
              }
              vmDiskStat_lock.setNetBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
            }
            vmDiskStat_lock.setCurrentBytesWrite(vmDiskStat.getBytesWrite());
            if (!_dailyOrHourly) {
              vmDiskStat_lock.setAggIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
              vmDiskStat_lock.setAggIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
              vmDiskStat_lock.setAggBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
              vmDiskStat_lock.setAggBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
            }
            _vmDiskStatsDao.update(vmDiskStat_lock.getId(),vmDiskStat_lock);
          }
        }
      }
);
    }
 catch (    Exception e) {
      s_logger.warn("String_Node_Str" + userVm.getId() + "String_Node_Str"+ hostId,e);
    }
  }
}

Fixed version (ground truth):
@Override public void collectVmDiskStatistics(final UserVmVO userVm){
  if (!userVm.getHypervisorType().equals(HypervisorType.KVM))   return;
  s_logger.debug("String_Node_Str");
  long hostId=userVm.getHostId();
  List<String> vmNames=new ArrayList<String>();
  vmNames.add(userVm.getInstanceName());
  final HostVO host=_hostDao.findById(hostId);
  GetVmDiskStatsAnswer diskStatsAnswer=null;
  try {
    diskStatsAnswer=(GetVmDiskStatsAnswer)_agentMgr.easySend(hostId,new GetVmDiskStatsCommand(vmNames,host.getGuid(),host.getName()));
  }
 catch (  Exception e) {
    s_logger.warn("String_Node_Str" + userVm.getHostName() + "String_Node_Str"+ host.getName(),e);
    return;
  }
  if (diskStatsAnswer != null) {
    if (!diskStatsAnswer.getResult()) {
      s_logger.warn("String_Node_Str" + userVm.getHostName() + "String_Node_Str"+ host.getName()+ "String_Node_Str"+ diskStatsAnswer.getDetails());
      return;
    }
    try {
      final GetVmDiskStatsAnswer diskStatsAnswerFinal=diskStatsAnswer;
      Transaction.execute(new TransactionCallbackNoReturn(){
        @Override public void doInTransactionWithoutResult(        TransactionStatus status){
          HashMap<String,List<VmDiskStatsEntry>> vmDiskStatsByName=diskStatsAnswerFinal.getVmDiskStatsMap();
          if (vmDiskStatsByName == null)           return;
          List<VmDiskStatsEntry> vmDiskStats=vmDiskStatsByName.get(userVm.getInstanceName());
          if (vmDiskStats == null)           return;
          for (          VmDiskStatsEntry vmDiskStat : vmDiskStats) {
            SearchCriteria<VolumeVO> sc_volume=_volsDao.createSearchCriteria();
            sc_volume.addAnd("String_Node_Str",SearchCriteria.Op.EQ,vmDiskStat.getPath());
            List<VolumeVO> volumes=_volsDao.search(sc_volume,null);
            if ((volumes == null) || (volumes.size() == 0))             break;
            VolumeVO volume=volumes.get(0);
            VmDiskStatisticsVO previousVmDiskStats=_vmDiskStatsDao.findBy(userVm.getAccountId(),userVm.getDataCenterId(),userVm.getId(),volume.getId());
            VmDiskStatisticsVO vmDiskStat_lock=_vmDiskStatsDao.lock(userVm.getAccountId(),userVm.getDataCenterId(),userVm.getId(),volume.getId());
            if ((vmDiskStat.getIORead() == 0) && (vmDiskStat.getIOWrite() == 0) && (vmDiskStat.getBytesRead() == 0)&& (vmDiskStat.getBytesWrite() == 0)) {
              s_logger.debug("String_Node_Str");
              continue;
            }
            if (vmDiskStat_lock == null) {
              s_logger.warn("String_Node_Str" + userVm.getAccountId() + "String_Node_Str"+ userVm.getId()+ "String_Node_Str"+ volume.getId());
              continue;
            }
            if (previousVmDiskStats != null && ((previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead()) || ((previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock.getCurrentIOWrite()) || (previousVmDiskStats.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats.getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite())))) {
              s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat.getIOWrite()+ "String_Node_Str"+ vmDiskStat.getBytesRead()+ "String_Node_Str"+ vmDiskStat.getBytesWrite());
              continue;
            }
            if (vmDiskStat_lock.getCurrentIORead() > vmDiskStat.getIORead()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentIORead());
              }
              vmDiskStat_lock.setNetIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
            }
            vmDiskStat_lock.setCurrentIORead(vmDiskStat.getIORead());
            if (vmDiskStat_lock.getCurrentIOWrite() > vmDiskStat.getIOWrite()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getIOWrite()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentIOWrite());
              }
              vmDiskStat_lock.setNetIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
            }
            vmDiskStat_lock.setCurrentIOWrite(vmDiskStat.getIOWrite());
            if (vmDiskStat_lock.getCurrentBytesRead() > vmDiskStat.getBytesRead()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getBytesRead()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentBytesRead());
              }
              vmDiskStat_lock.setNetBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
            }
            vmDiskStat_lock.setCurrentBytesRead(vmDiskStat.getBytesRead());
            if (vmDiskStat_lock.getCurrentBytesWrite() > vmDiskStat.getBytesWrite()) {
              if (s_logger.isDebugEnabled()) {
                s_logger.debug("String_Node_Str" + "String_Node_Str" + host.getName() + "String_Node_Str"+ vmDiskStat.getVmName()+ "String_Node_Str"+ vmDiskStat.getBytesWrite()+ "String_Node_Str"+ vmDiskStat_lock.getCurrentBytesWrite());
              }
              vmDiskStat_lock.setNetBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
            }
            vmDiskStat_lock.setCurrentBytesWrite(vmDiskStat.getBytesWrite());
            if (!_dailyOrHourly) {
              vmDiskStat_lock.setAggIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
              vmDiskStat_lock.setAggIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
              vmDiskStat_lock.setAggBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
              vmDiskStat_lock.setAggBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
            }
            _vmDiskStatsDao.update(vmDiskStat_lock.getId(),vmDiskStat_lock);
          }
        }
      }
);
    }
 catch (    Exception e) {
      s_logger.warn("String_Node_Str" + userVm.getId() + "String_Node_Str"+ hostId,e);
    }
  }
}