Program: 89592
Project: 89592
Buggy source:
@Override @DB public Network createNetwork(long networkOfferingId,String name,String displayText,Boolean isShared,Boolean isDefault,Long zoneId,String gateway,String cidr,String vlanId,String networkDomain,Account owner,boolean isSecurityGroupEnabled,Long domainId,List<String> tags) throws ConcurrentOperationException, InsufficientCapacityException {
  NetworkOfferingVO networkOffering=_networkOfferingDao.findById(networkOfferingId);
  DataCenterVO zone=_dcDao.findById(zoneId);
  if (zone.isSecurityGroupEnabled() && (networkOffering.getGuestType() == GuestIpType.Virtual || (isShared != null && isShared))) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (zone.getNetworkType() == NetworkType.Basic) {
    throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic);
  }
  if (networkOffering.getGuestType() == GuestIpType.Virtual) {
    if (isDefault != null && !isDefault) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else {
      isDefault=true;
    }
    if (isShared != null && isShared) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else {
    if (isDefault == null) {
      isDefault=false;
    }
  }
  if (isShared) {
    owner=_accountMgr.getSystemAccount();
  }
  if (vlanId != null) {
    String uri="String_Node_Str" + vlanId;
    List<NetworkVO> networks=_networksDao.listBy(zoneId,uri);
    if ((networks != null && !networks.isEmpty())) {
      throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ zoneId);
    }
  }
  if (vlanId != null && !networkOffering.getSpecifyVlan()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (networkOffering.getGuestType() == GuestIpType.Virtual && vlanId != null) {
    throw new InvalidParameterValueException("String_Node_Str" + GuestIpType.Virtual);
  }
  if (networkDomain == null) {
    networkDomain="String_Node_Str" + Long.toHexString(owner.getId()) + _networkDomain;
  }
 else {
    if (!NetUtils.verifyDomainName(networkDomain)) {
      throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    }
  }
  if (cidr == null && networkOffering.getTrafficType() == TrafficType.Guest && networkOffering.getGuestType() == GuestIpType.Direct) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (cidr != null && networkOffering.getGuestType() == GuestIpType.Virtual && networkOffering.getTrafficType() == TrafficType.Guest) {
    if (!NetUtils.validateGuestCidr(cidr)) {
      throw new InvalidParameterValueException("String_Node_Str" + cidr + "String_Node_Str");
    }
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  DataCenterDeployment plan=new DataCenterDeployment(zoneId,null,null,null,null);
  NetworkVO userNetwork=new NetworkVO();
  userNetwork.setNetworkDomain(networkDomain);
  userNetwork.setSecurityGroupEnabled(isSecurityGroupEnabled);
  if (cidr != null && gateway != null) {
    userNetwork.setCidr(cidr);
    userNetwork.setGateway(gateway);
    if (vlanId != null) {
      userNetwork.setBroadcastUri(URI.create("String_Node_Str" + vlanId));
      userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
      if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
        userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
      }
 else {
        userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
      }
    }
  }
  List<NetworkVO> networks=setupNetwork(owner,networkOffering,userNetwork,plan,name,displayText,isShared,isDefault,true,domainId,tags);
  Network network=null;
  if (networks == null || networks.isEmpty()) {
    throw new CloudRuntimeException("String_Node_Str");
  }
 else {
    if (networks.size() > 0 && networks.get(0).getGuestType() == GuestIpType.Virtual && networks.get(0).getTrafficType() == TrafficType.Guest) {
      Network defaultGuestNetwork=networks.get(0);
      for (      Network nw : networks) {
        if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) {
          defaultGuestNetwork=nw;
        }
      }
      network=defaultGuestNetwork;
    }
 else {
      network=networks.get(0);
    }
  }
  txn.commit();
  UserContext.current().setEventDetails("String_Node_Str" + network.getId());
  return network;
}

Fixed version (ground truth):
@Override @DB public Network createNetwork(long networkOfferingId,String name,String displayText,Boolean isShared,Boolean isDefault,Long zoneId,String gateway,String cidr,String vlanId,String networkDomain,Account owner,boolean isSecurityGroupEnabled,Long domainId,List<String> tags) throws ConcurrentOperationException, InsufficientCapacityException {
  NetworkOfferingVO networkOffering=_networkOfferingDao.findById(networkOfferingId);
  DataCenterVO zone=_dcDao.findById(zoneId);
  if (zone.isSecurityGroupEnabled() && (networkOffering.getGuestType() == GuestIpType.Virtual || (isShared != null && isShared))) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (zone.getNetworkType() == NetworkType.Basic) {
    throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic);
  }
  if (networkOffering.getGuestType() == GuestIpType.Virtual) {
    if (isDefault != null && !isDefault) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else {
      isDefault=true;
    }
    if (isShared != null && isShared) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else {
    if (isDefault == null) {
      isDefault=false;
    }
  }
  if (isShared) {
    owner=_accountMgr.getSystemAccount();
  }
  if (vlanId != null) {
    String uri="String_Node_Str" + vlanId;
    List<NetworkVO> networks=_networksDao.listBy(zoneId,uri);
    if ((networks != null && !networks.isEmpty())) {
      throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ zoneId);
    }
  }
  if (vlanId != null && !networkOffering.getSpecifyVlan()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (networkOffering.getGuestType() == GuestIpType.Virtual && vlanId != null) {
    throw new InvalidParameterValueException("String_Node_Str" + GuestIpType.Virtual);
  }
  Map<Network.Capability,String> dnsCapabilities=getServiceCapabilities(zoneId,networkOfferingId,Service.Dns);
  String isUpdateDnsSupported=dnsCapabilities.get(Capability.AllowDnsSuffixModification);
  if (isUpdateDnsSupported == null || !Boolean.valueOf(isUpdateDnsSupported)) {
    if (networkDomain != null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkOfferingId + "String_Node_Str"+ zoneId);
    }
  }
 else {
    if (networkDomain == null) {
      networkDomain="String_Node_Str" + Long.toHexString(owner.getId()) + _networkDomain;
    }
 else {
      if (!NetUtils.verifyDomainName(networkDomain)) {
        throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
      }
    }
  }
  if (cidr == null && networkOffering.getTrafficType() == TrafficType.Guest && networkOffering.getGuestType() == GuestIpType.Direct) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (cidr != null && networkOffering.getGuestType() == GuestIpType.Virtual && networkOffering.getTrafficType() == TrafficType.Guest) {
    if (!NetUtils.validateGuestCidr(cidr)) {
      throw new InvalidParameterValueException("String_Node_Str" + cidr + "String_Node_Str");
    }
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  DataCenterDeployment plan=new DataCenterDeployment(zoneId,null,null,null,null);
  NetworkVO userNetwork=new NetworkVO();
  userNetwork.setNetworkDomain(networkDomain);
  userNetwork.setSecurityGroupEnabled(isSecurityGroupEnabled);
  if (cidr != null && gateway != null) {
    userNetwork.setCidr(cidr);
    userNetwork.setGateway(gateway);
    if (vlanId != null) {
      userNetwork.setBroadcastUri(URI.create("String_Node_Str" + vlanId));
      userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
      if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
        userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
      }
 else {
        userNetwork.setBroadcastDomainType(BroadcastDomainType.Native);
      }
    }
  }
  List<NetworkVO> networks=setupNetwork(owner,networkOffering,userNetwork,plan,name,displayText,isShared,isDefault,true,domainId,tags);
  Network network=null;
  if (networks == null || networks.isEmpty()) {
    throw new CloudRuntimeException("String_Node_Str");
  }
 else {
    if (networks.size() > 0 && networks.get(0).getGuestType() == GuestIpType.Virtual && networks.get(0).getTrafficType() == TrafficType.Guest) {
      Network defaultGuestNetwork=networks.get(0);
      for (      Network nw : networks) {
        if (nw.getCidr() != null && nw.getCidr().equals(zone.getGuestNetworkCidr())) {
          defaultGuestNetwork=nw;
        }
      }
      network=defaultGuestNetwork;
    }
 else {
      network=networks.get(0);
    }
  }
  txn.commit();
  UserContext.current().setEventDetails("String_Node_Str" + network.getId());
  return network;
}