Program: 107177
Project: 107177
Buggy source:
@Override public boolean cleanupAccount(AccountVO account,long callerUserId,Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
  long accountId=account.getId();
  boolean accountCleanupNeeded=false;
  try {
    List<InstanceGroupVO> groups=_vmGroupDao.listByAccountId(accountId);
    for (    InstanceGroupVO group : groups) {
      if (!_vmMgr.deleteVmGroup(group.getId())) {
        s_logger.error("String_Node_Str" + group.getId());
        accountCleanupNeeded=true;
      }
    }
    boolean success=_snapMgr.deleteSnapshotDirsForAccount(accountId);
    if (success) {
      s_logger.debug("String_Node_Str" + accountId + "String_Node_Str");
    }
    List<VMTemplateVO> userTemplates=_templateDao.listByAccountId(accountId);
    boolean allTemplatesDeleted=true;
    for (    VMTemplateVO template : userTemplates) {
      try {
        allTemplatesDeleted=_tmpltMgr.delete(callerUserId,template.getId(),null);
      }
 catch (      Exception e) {
        s_logger.warn("String_Node_Str" + template.getName() + "String_Node_Str"+ e.getMessage());
        allTemplatesDeleted=false;
      }
    }
    if (!allTemplatesDeleted) {
      s_logger.warn("String_Node_Str" + accountId);
      accountCleanupNeeded=true;
    }
    List<UserVmVO> vms=_userVmDao.listByAccountId(accountId);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + accountId + "String_Node_Str"+ vms.size());
    }
    for (    UserVmVO vm : vms) {
      if (!_vmMgr.expunge(vm,callerUserId,caller)) {
        s_logger.error("String_Node_Str" + vm.getId());
        accountCleanupNeeded=true;
      }
    }
    List<VolumeVO> volumes=_volumeDao.findDetachedByAccount(accountId);
    for (    VolumeVO volume : volumes) {
      if (!volume.getState().equals(Volume.State.Destroy)) {
        _storageMgr.destroyVolume(volume);
      }
    }
    int numRemoved=_securityGroupDao.removeByAccountId(accountId);
    s_logger.info("String_Node_Str" + numRemoved + "String_Node_Str"+ accountId);
    boolean networksDeleted=true;
    s_logger.debug("String_Node_Str" + account.getId());
    List<NetworkVO> networks=_networkDao.listByOwner(accountId);
    if (networks != null) {
      for (      NetworkVO network : networks) {
        if (!_networkMgr.deleteNetworkInternal(network.getId(),callerUserId)) {
          s_logger.warn("String_Node_Str" + network + "String_Node_Str"+ accountId+ "String_Node_Str");
          accountCleanupNeeded=true;
          networksDeleted=false;
        }
 else {
          s_logger.debug("String_Node_Str" + network.getId() + "String_Node_Str"+ accountId+ "String_Node_Str");
        }
      }
    }
    if (networksDeleted) {
      if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)) {
        accountCleanupNeeded=true;
      }
 else {
        s_logger.debug("String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str");
      }
    }
    return true;
  }
  finally {
    s_logger.info("String_Node_Str" + account.getId() + (accountCleanupNeeded ? "String_Node_Str" : "String_Node_Str"));
    if (accountCleanupNeeded) {
      _accountDao.markForCleanup(accountId);
    }
  }
}

Fixed version (ground truth):
@Override public boolean cleanupAccount(AccountVO account,long callerUserId,Account caller) throws ConcurrentOperationException, ResourceUnavailableException {
  long accountId=account.getId();
  boolean accountCleanupNeeded=false;
  try {
    List<InstanceGroupVO> groups=_vmGroupDao.listByAccountId(accountId);
    for (    InstanceGroupVO group : groups) {
      if (!_vmMgr.deleteVmGroup(group.getId())) {
        s_logger.error("String_Node_Str" + group.getId());
        accountCleanupNeeded=true;
      }
    }
    boolean success=_snapMgr.deleteSnapshotDirsForAccount(accountId);
    if (success) {
      s_logger.debug("String_Node_Str" + accountId + "String_Node_Str");
    }
    List<VMTemplateVO> userTemplates=_templateDao.listByAccountId(accountId);
    boolean allTemplatesDeleted=true;
    for (    VMTemplateVO template : userTemplates) {
      try {
        allTemplatesDeleted=_tmpltMgr.delete(callerUserId,template.getId(),null);
      }
 catch (      Exception e) {
        s_logger.warn("String_Node_Str" + template.getName() + "String_Node_Str"+ e.getMessage());
        allTemplatesDeleted=false;
      }
    }
    if (!allTemplatesDeleted) {
      s_logger.warn("String_Node_Str" + accountId);
      accountCleanupNeeded=true;
    }
    List<UserVmVO> vms=_userVmDao.listByAccountId(accountId);
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + accountId + "String_Node_Str"+ vms.size());
    }
    for (    UserVmVO vm : vms) {
      if (!_vmMgr.expunge(vm,callerUserId,caller)) {
        s_logger.error("String_Node_Str" + vm.getId());
        accountCleanupNeeded=true;
      }
      UsageEventVO usageEvent=new UsageEventVO(EventTypes.EVENT_VM_DESTROY,vm.getAccountId(),vm.getDataCenterId(),vm.getId(),vm.getName(),vm.getServiceOfferingId(),vm.getTemplateId(),null);
      _usageEventDao.persist(usageEvent);
    }
    List<VolumeVO> volumes=_volumeDao.findDetachedByAccount(accountId);
    for (    VolumeVO volume : volumes) {
      if (!volume.getState().equals(Volume.State.Destroy)) {
        _storageMgr.destroyVolume(volume);
        if (volume.getPoolId() != null) {
          UsageEventVO usageEvent=new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName(),null,null,null);
          _usageEventDao.persist(usageEvent);
        }
      }
    }
    int numRemoved=_securityGroupDao.removeByAccountId(accountId);
    s_logger.info("String_Node_Str" + numRemoved + "String_Node_Str"+ accountId);
    boolean networksDeleted=true;
    s_logger.debug("String_Node_Str" + account.getId());
    List<NetworkVO> networks=_networkDao.listByOwner(accountId);
    if (networks != null) {
      for (      NetworkVO network : networks) {
        if (!_networkMgr.deleteNetworkInternal(network.getId(),callerUserId)) {
          s_logger.warn("String_Node_Str" + network + "String_Node_Str"+ accountId+ "String_Node_Str");
          accountCleanupNeeded=true;
          networksDeleted=false;
        }
 else {
          s_logger.debug("String_Node_Str" + network.getId() + "String_Node_Str"+ accountId+ "String_Node_Str");
        }
      }
    }
    if (networksDeleted) {
      if (!_configMgr.deleteAccountSpecificVirtualRanges(accountId)) {
        accountCleanupNeeded=true;
      }
 else {
        s_logger.debug("String_Node_Str" + "String_Node_Str" + accountId + "String_Node_Str");
      }
    }
    return true;
  }
  finally {
    s_logger.info("String_Node_Str" + account.getId() + (accountCleanupNeeded ? "String_Node_Str" : "String_Node_Str"));
    if (accountCleanupNeeded) {
      _accountDao.markForCleanup(accountId);
    }
  }
}