Program: 106121
Project: 106121
Buggy source:
@Override @DB public boolean destroyNetwork(long networkId,final ReservationContext context){
  final Account callerAccount=context.getAccount();
  NetworkVO network=_networksDao.findById(networkId);
  if (network == null) {
    s_logger.debug("String_Node_Str" + networkId);
    return false;
  }
  List<UserVmVO> userVms=_userVmDao.listByNetworkIdAndStates(networkId);
  for (  UserVmVO vm : userVms) {
    if (!(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;
    }
  }
  int nicCount=getActiveNicsInNetwork(networkId);
  if (nicCount > 0) {
    s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
    _networksDao.changeActiveNicsBy(networkId,(-1 * nicCount));
  }
  DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
  if (zone.getNetworkType() == NetworkType.Basic) {
    List<VMInstanceVO> systemVms=_vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(),Type.ConsoleProxy,Type.SecondaryStorageVm);
    if (systemVms != null && !systemVms.isEmpty()) {
      s_logger.warn("String_Node_Str");
      return false;
    }
  }
  shutdownNetwork(networkId,context,false);
  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;
  if (!cleanupNetworkResources(networkId,callerAccount,context.getCaller().getId())) {
    s_logger.warn("String_Node_Str" + networkId + "String_Node_Str");
    return false;
  }
  List<Provider> providersToDestroy=getNetworkProviders(network.getId());
  for (  NetworkElement element : _networkElements) {
    if (providersToDestroy.contains(element.getProvider())) {
      try {
        if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network),element.getProvider().getName())) {
          s_logger.warn("String_Node_Str" + element.getName() + "String_Node_Str"+ _networkModel.getPhysicalNetworkId(network));
          success=false;
        }
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + element);
        }
        if (!element.destroy(network,context)) {
          success=false;
          s_logger.warn("String_Node_Str" + element.getName());
        }
      }
 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");
    }
    final NetworkVO networkFinal=network;
    try {
      Transaction.execute(new TransactionCallbackNoReturn(){
        @Override public void doInTransactionWithoutResult(        TransactionStatus status){
          NetworkGuru guru=AdapterBase.getAdapterByName(_networkGurus,networkFinal.getGuruName());
          guru.trash(networkFinal,_networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
          if (!deleteVlansInNetwork(networkFinal.getId(),context.getCaller().getId(),callerAccount)) {
            s_logger.warn("String_Node_Str" + networkFinal + "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + networkFinal + "String_Node_Str");
          }
 else {
            try {
              stateTransitTo(networkFinal,Event.DestroyNetwork);
            }
 catch (            NoTransitionException e) {
              s_logger.debug(e.getMessage());
            }
            if (_networksDao.remove(networkFinal.getId())) {
              NetworkDomainVO networkDomain=_networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId());
              if (networkDomain != null)               _networkDomainDao.remove(networkDomain.getId());
              NetworkAccountVO networkAccount=_networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
              if (networkAccount != null)               _networkAccountDao.remove(networkAccount.getId());
            }
            NetworkOffering ntwkOff=_entityMgr.findById(NetworkOffering.class,networkFinal.getNetworkOfferingId());
            boolean updateResourceCount=resourceCountNeedsUpdate(ntwkOff,networkFinal.getAclType());
            if (updateResourceCount) {
              _resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(),ResourceType.network);
            }
          }
        }
      }
);
      return false;
    }
 catch (    CloudRuntimeException e) {
      s_logger.error("String_Node_Str",e);
      return false;
    }
  }
  return success;
}

Fixed version (ground truth):
@Override @DB public boolean destroyNetwork(long networkId,final ReservationContext context){
  final Account callerAccount=context.getAccount();
  NetworkVO network=_networksDao.findById(networkId);
  if (network == null) {
    s_logger.debug("String_Node_Str" + networkId);
    return false;
  }
  List<UserVmVO> userVms=_userVmDao.listByNetworkIdAndStates(networkId);
  for (  UserVmVO vm : userVms) {
    if (!(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;
    }
  }
  int nicCount=getActiveNicsInNetwork(networkId);
  if (nicCount > 0) {
    s_logger.debug("String_Node_Str" + networkId + "String_Node_Str");
    _networksDao.changeActiveNicsBy(networkId,(-1 * nicCount));
  }
  DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
  if (zone.getNetworkType() == NetworkType.Basic) {
    List<VMInstanceVO> systemVms=_vmDao.listNonRemovedVmsByTypeAndNetwork(network.getId(),Type.ConsoleProxy,Type.SecondaryStorageVm);
    if (systemVms != null && !systemVms.isEmpty()) {
      s_logger.warn("String_Node_Str");
      return false;
    }
  }
  shutdownNetwork(networkId,context,false);
  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;
  if (!cleanupNetworkResources(networkId,callerAccount,context.getCaller().getId())) {
    s_logger.warn("String_Node_Str" + networkId + "String_Node_Str");
    return false;
  }
  List<Provider> providersToDestroy=getNetworkProviders(network.getId());
  for (  NetworkElement element : _networkElements) {
    if (providersToDestroy.contains(element.getProvider())) {
      try {
        if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network),element.getProvider().getName())) {
          s_logger.warn("String_Node_Str" + element.getName() + "String_Node_Str"+ _networkModel.getPhysicalNetworkId(network));
          success=false;
        }
        if (s_logger.isDebugEnabled()) {
          s_logger.debug("String_Node_Str" + element);
        }
        if (!element.destroy(network,context)) {
          success=false;
          s_logger.warn("String_Node_Str" + element.getName());
        }
      }
 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");
    }
    final NetworkVO networkFinal=network;
    try {
      Transaction.execute(new TransactionCallbackNoReturn(){
        @Override public void doInTransactionWithoutResult(        TransactionStatus status){
          NetworkGuru guru=AdapterBase.getAdapterByName(_networkGurus,networkFinal.getGuruName());
          guru.trash(networkFinal,_networkOfferingDao.findById(networkFinal.getNetworkOfferingId()));
          if (!deleteVlansInNetwork(networkFinal.getId(),context.getCaller().getId(),callerAccount)) {
            s_logger.warn("String_Node_Str" + networkFinal + "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + networkFinal + "String_Node_Str");
          }
 else {
            try {
              stateTransitTo(networkFinal,Event.DestroyNetwork);
            }
 catch (            NoTransitionException e) {
              s_logger.debug(e.getMessage());
            }
            if (_networksDao.remove(networkFinal.getId())) {
              NetworkDomainVO networkDomain=_networkDomainDao.getDomainNetworkMapByNetworkId(networkFinal.getId());
              if (networkDomain != null)               _networkDomainDao.remove(networkDomain.getId());
              NetworkAccountVO networkAccount=_networkAccountDao.getAccountNetworkMapByNetworkId(networkFinal.getId());
              if (networkAccount != null)               _networkAccountDao.remove(networkAccount.getId());
            }
            NetworkOffering ntwkOff=_entityMgr.findById(NetworkOffering.class,networkFinal.getNetworkOfferingId());
            boolean updateResourceCount=resourceCountNeedsUpdate(ntwkOff,networkFinal.getAclType());
            if (updateResourceCount) {
              _resourceLimitMgr.decrementResourceCount(networkFinal.getAccountId(),ResourceType.network);
            }
          }
        }
      }
);
      return true;
    }
 catch (    CloudRuntimeException e) {
      s_logger.error("String_Node_Str",e);
      return false;
    }
  }
  return success;
}