Program: 106091
Project: 106091
Buggy source:
@Override public void doInTransactionWithoutResult(TransactionStatus status){
  SearchCriteria<HostVO> sc=_hostDao.createSearchCriteria();
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,Status.Up.toString());
  sc.addAnd("String_Node_Str",SearchCriteria.Op.NIN,ResourceState.Maintenance,ResourceState.PrepareForMaintenance,ResourceState.ErrorInMaintenance);
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,Host.Type.Routing.toString());
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,HypervisorType.KVM);
  List<HostVO> hosts=_hostDao.search(sc,null);
  for (  HostVO host : hosts) {
    List<UserVmVO> vms=_userVmDao.listRunningByHostId(host.getId());
    List<Long> vmIds=new ArrayList<Long>();
    for (    UserVmVO vm : vms) {
      if (vm.getType() == VirtualMachine.Type.User)       vmIds.add(vm.getId());
    }
    HashMap<Long,List<VmDiskStatsEntry>> vmDiskStatsById=_userVmMgr.getVmDiskStatistics(host.getId(),host.getName(),vmIds);
    if (vmDiskStatsById == null)     continue;
    Set<Long> vmIdSet=vmDiskStatsById.keySet();
    for (    Long vmId : vmIdSet) {
      List<VmDiskStatsEntry> vmDiskStats=vmDiskStatsById.get(vmId);
      if (vmDiskStats == null)       continue;
      UserVmVO userVm=_userVmDao.findById(vmId);
      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(),vmId,volume.getId());
        VmDiskStatisticsVO vmDiskStat_lock=_vmDiskStatsDao.lock(userVm.getAccountId(),userVm.getDataCenterId(),vmId,volume.getId());
        if ((vmDiskStat.getBytesRead() == 0) && (vmDiskStat.getBytesWrite() == 0) && (vmDiskStat.getIORead() == 0)&& (vmDiskStat.getIOWrite() == 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.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats.getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite()) || (previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead())|| (previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock.getCurrentIOWrite()))) {
          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.getBytesWrite()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat.getIOWrite());
          continue;
        }
        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 (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 (!_dailyOrHourly) {
          vmDiskStat_lock.setAggBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
          vmDiskStat_lock.setAggBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
          vmDiskStat_lock.setAggIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
          vmDiskStat_lock.setAggIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
        }
        _vmDiskStatsDao.update(vmDiskStat_lock.getId(),vmDiskStat_lock);
      }
    }
  }
}

Fixed version (ground truth):
@Override public void doInTransactionWithoutResult(TransactionStatus status){
  SearchCriteria<HostVO> sc=_hostDao.createSearchCriteria();
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,Status.Up.toString());
  sc.addAnd("String_Node_Str",SearchCriteria.Op.NIN,ResourceState.Maintenance,ResourceState.PrepareForMaintenance,ResourceState.ErrorInMaintenance);
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,Host.Type.Routing.toString());
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,HypervisorType.KVM);
  List<HostVO> hosts=_hostDao.search(sc,null);
  for (  HostVO host : hosts) {
    List<UserVmVO> vms=_userVmDao.listRunningByHostId(host.getId());
    List<Long> vmIds=new ArrayList<Long>();
    for (    UserVmVO vm : vms) {
      if (vm.getType() == VirtualMachine.Type.User)       vmIds.add(vm.getId());
    }
    HashMap<Long,List<VmDiskStatsEntry>> vmDiskStatsById=_userVmMgr.getVmDiskStatistics(host.getId(),host.getName(),vmIds);
    if (vmDiskStatsById == null)     continue;
    Set<Long> vmIdSet=vmDiskStatsById.keySet();
    for (    Long vmId : vmIdSet) {
      List<VmDiskStatsEntry> vmDiskStats=vmDiskStatsById.get(vmId);
      if (vmDiskStats == null)       continue;
      UserVmVO userVm=_userVmDao.findById(vmId);
      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(),vmId,volume.getId());
        VmDiskStatisticsVO vmDiskStat_lock=_vmDiskStatsDao.lock(userVm.getAccountId(),userVm.getDataCenterId(),vmId,volume.getId());
        if ((vmDiskStat.getBytesRead() == 0) && (vmDiskStat.getBytesWrite() == 0) && (vmDiskStat.getIORead() == 0)&& (vmDiskStat.getIOWrite() == 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.getCurrentBytesRead() != vmDiskStat_lock.getCurrentBytesRead()) || (previousVmDiskStats.getCurrentBytesWrite() != vmDiskStat_lock.getCurrentBytesWrite()) || (previousVmDiskStats.getCurrentIORead() != vmDiskStat_lock.getCurrentIORead())|| (previousVmDiskStats.getCurrentIOWrite() != vmDiskStat_lock.getCurrentIOWrite()))) {
          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.getBytesWrite()+ "String_Node_Str"+ vmDiskStat.getIORead()+ "String_Node_Str"+ vmDiskStat.getIOWrite());
          continue;
        }
        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 (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 (!_dailyOrHourly) {
          vmDiskStat_lock.setAggBytesWrite(vmDiskStat_lock.getNetBytesWrite() + vmDiskStat_lock.getCurrentBytesWrite());
          vmDiskStat_lock.setAggBytesRead(vmDiskStat_lock.getNetBytesRead() + vmDiskStat_lock.getCurrentBytesRead());
          vmDiskStat_lock.setAggIOWrite(vmDiskStat_lock.getNetIOWrite() + vmDiskStat_lock.getCurrentIOWrite());
          vmDiskStat_lock.setAggIORead(vmDiskStat_lock.getNetIORead() + vmDiskStat_lock.getCurrentIORead());
        }
        _vmDiskStatsDao.update(vmDiskStat_lock.getId(),vmDiskStat_lock);
      }
    }
  }
}