Program: 107142
Project: 107142
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);
        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(),vm.getHypervisorType().toString());
      _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());
          _usageEventDao.persist(usageEvent);
        }
      }
    }
    List<RemoteAccessVpnVO> remoteAccessVpns=_remoteAccessVpnDao.findByAccount(accountId);
    List<VpnUserVO> vpnUsers=_vpnUser.listByAccount(accountId);
    for (    VpnUserVO vpnUser : vpnUsers) {
      _remoteAccessVpnMgr.removeVpnUser(accountId,vpnUser.getUsername());
    }
    for (    RemoteAccessVpnVO vpn : remoteAccessVpns) {
      _remoteAccessVpnMgr.destroyRemoteAccessVpn(vpn.getServerAddressId());
    }
    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) {
        ReservationContext context=new ReservationContextImpl(null,null,getActiveUser(callerUserId),account);
        if (!_networkMgr.deleteNetworkInternal(network.getId(),context)) {
          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){
  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);
        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(),vm.getHypervisorType().toString());
      _usageEventDao.persist(usageEvent);
    }
    List<VolumeVO> volumes=_volumeDao.findDetachedByAccount(accountId);
    for (    VolumeVO volume : volumes) {
      if (!volume.getState().equals(Volume.State.Destroy)) {
        try {
          _storageMgr.destroyVolume(volume);
          if (volume.getPoolId() != null) {
            UsageEventVO usageEvent=new UsageEventVO(EventTypes.EVENT_VOLUME_DELETE,volume.getAccountId(),volume.getDataCenterId(),volume.getId(),volume.getName());
            _usageEventDao.persist(usageEvent);
          }
        }
 catch (        ConcurrentOperationException ex) {
          s_logger.warn("String_Node_Str" + accountId + "String_Node_Str",ex);
          accountCleanupNeeded=true;
        }
      }
    }
    List<RemoteAccessVpnVO> remoteAccessVpns=_remoteAccessVpnDao.findByAccount(accountId);
    List<VpnUserVO> vpnUsers=_vpnUser.listByAccount(accountId);
    for (    VpnUserVO vpnUser : vpnUsers) {
      _remoteAccessVpnMgr.removeVpnUser(accountId,vpnUser.getUsername());
    }
    try {
      for (      RemoteAccessVpnVO vpn : remoteAccessVpns) {
        _remoteAccessVpnMgr.destroyRemoteAccessVpn(vpn.getServerAddressId());
      }
    }
 catch (    ResourceUnavailableException ex) {
      s_logger.warn("String_Node_Str" + accountId + "String_Node_Str",ex);
      accountCleanupNeeded=true;
    }
    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) {
        ReservationContext context=new ReservationContextImpl(null,null,getActiveUser(callerUserId),account);
        if (!_networkMgr.destroyNetwork(network.getId(),context)) {
          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);
    }
  }
}