Program: 107137
Project: 107137
Buggy source:
@Override @DB public boolean destroyNetwork(long networkId,ReservationContext context){
  Account callerAccount=_accountMgr.getAccount(context.getCaller().getAccountId());
  NetworkVO network=_networksDao.findById(networkId);
  if (network == null) {
    s_logger.debug("String_Node_Str" + networkId);
    return false;
  }
  shutdownNetwork(networkId,context);
  network=_networksDao.findById(networkId);
  if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup) {
    s_logger.debug("String_Node_Str" + network.getState());
    return false;
  }
  boolean success=true;
  cleanupNetworkResources(networkId,callerAccount,context.getCaller().getId());
  for (  NetworkElement element : _networkElements) {
    try {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + element);
      }
      element.destroy(network);
    }
 catch (    ResourceUnavailableException e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
catch (    ConcurrentOperationException e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
catch (    Exception e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
  }
  if (success) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
    }
    NetworkGuru guru=_networkGurus.get(network.getGuruName());
    Account owner=_accountMgr.getAccount(network.getAccountId());
    Transaction txn=Transaction.currentTxn();
    txn.start();
    guru.trash(network,_networkOfferingDao.findById(network.getNetworkOfferingId()),owner);
    if (!deleteVlansInNetwork(network.getId(),context.getCaller().getId())) {
      success=false;
      s_logger.warn("String_Node_Str" + network + "String_Node_Str");
    }
 else {
      network.setState(Network.State.Destroy);
      _networksDao.update(network.getId(),network);
      _networksDao.remove(network.getId());
      txn.commit();
    }
  }
  return success;
}

Fixed version (ground truth):
@Override @DB public boolean destroyNetwork(long networkId,ReservationContext context){
  Account callerAccount=_accountMgr.getAccount(context.getCaller().getAccountId());
  NetworkVO network=_networksDao.findById(networkId);
  if (network == null) {
    s_logger.debug("String_Node_Str" + networkId);
    return false;
  }
  int nicCount=getActiveNicsInNetwork(networkId);
  if (nicCount > 0) {
    s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
    return false;
  }
  List<UserVmVO> userVms=_vmDao.listByNetworkId(networkId);
  for (  UserVmVO vm : userVms) {
    if (!(vm.getState() == VirtualMachine.State.Error || (vm.getState() == VirtualMachine.State.Expunging && vm.getRemoved() != null))) {
      s_logger.warn("String_Node_Str" + vm + "String_Node_Str"+ vm.getState()+ "String_Node_Str");
      return false;
    }
  }
  shutdownNetwork(networkId,context);
  network=_networksDao.findById(networkId);
  if (network.getState() != Network.State.Allocated && network.getState() != Network.State.Setup) {
    s_logger.debug("String_Node_Str" + network.getState());
    return false;
  }
  boolean success=true;
  cleanupNetworkResources(networkId,callerAccount,context.getCaller().getId());
  for (  NetworkElement element : _networkElements) {
    try {
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + element);
      }
      element.destroy(network);
    }
 catch (    ResourceUnavailableException e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
catch (    ConcurrentOperationException e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
catch (    Exception e) {
      s_logger.warn("String_Node_Str" + element.getName(),e);
      success=false;
    }
  }
  if (success) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
    }
    NetworkGuru guru=_networkGurus.get(network.getGuruName());
    Account owner=_accountMgr.getAccount(network.getAccountId());
    Transaction txn=Transaction.currentTxn();
    txn.start();
    guru.trash(network,_networkOfferingDao.findById(network.getNetworkOfferingId()),owner);
    if (!deleteVlansInNetwork(network.getId(),context.getCaller().getId())) {
      success=false;
      s_logger.warn("String_Node_Str" + network + "String_Node_Str");
    }
 else {
      network.setState(Network.State.Destroy);
      _networksDao.update(network.getId(),network);
      _networksDao.remove(network.getId());
      txn.commit();
    }
  }
  return success;
}