Program: 106332
Project: 106332
Buggy source:
@Override @DB public Network createGuestNetwork(long networkOfferingId,String name,String displayText,String gateway,String cidr,String vlanId,String networkDomain,Account owner,Long domainId,PhysicalNetwork pNtwk,long zoneId,ACLType aclType,Boolean subdomainAccess,Long vpcId,String ip6Gateway,String ip6Cidr) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
}

Fixed version (ground truth):
@Override @DB public Network createGuestNetwork(long networkOfferingId,String name,String displayText,String gateway,String cidr,String vlanId,String networkDomain,Account owner,Long domainId,PhysicalNetwork pNtwk,long zoneId,ACLType aclType,Boolean subdomainAccess,Long vpcId,String ip6Gateway,String ip6Cidr) throws ConcurrentOperationException, InsufficientCapacityException, ResourceAllocationException {
  NetworkOfferingVO ntwkOff=_networkOfferingDao.findById(networkOfferingId);
  if (ntwkOff.getTrafficType() != TrafficType.Guest) {
    s_logger.warn("String_Node_Str");
    return null;
  }
  boolean updateResourceCount=resourceCountNeedsUpdate(ntwkOff,aclType);
  if (updateResourceCount) {
    _resourceLimitMgr.checkResourceLimit(owner,ResourceType.network);
  }
  if (ntwkOff.getState() != NetworkOffering.State.Enabled) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str" + NetworkOffering.State.Enabled);
    ex.addProxyObject(ntwkOff,ntwkOff.getId(),"String_Node_Str");
    throw ex;
  }
  if (pNtwk.getState() != PhysicalNetwork.State.Enabled) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str" + "String_Node_Str" + pNtwk.getState());
    ex.addProxyObject("String_Node_Str",pNtwk.getId(),"String_Node_Str");
    throw ex;
  }
  boolean ipv6=false;
  if (ip6Gateway != null && ip6Cidr != null) {
    ipv6=true;
  }
  DataCenterVO zone=_dcDao.findById(zoneId);
  if (zone.getNetworkType() == NetworkType.Basic) {
    if (ipv6) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (aclType == null || aclType != ACLType.Domain) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    List<NetworkVO> guestNetworks=_networksDao.listByZoneAndTrafficType(zone.getId(),TrafficType.Guest);
    if (!guestNetworks.isEmpty()) {
      throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic);
    }
    if (!(ntwkOff.getGuestType() == GuestType.Shared && !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(),Service.SourceNat))) {
      throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic + "String_Node_Str"+ "String_Node_Str"+ GuestType.Shared+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
    }
    if (domainId == null || domainId != Domain.ROOT_DOMAIN) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (subdomainAccess == null) {
      subdomainAccess=true;
    }
 else     if (!subdomainAccess) {
      throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    }
    if (vlanId == null) {
      vlanId=Vlan.UNTAGGED;
    }
 else {
      if (!vlanId.equalsIgnoreCase(Vlan.UNTAGGED)) {
        throw new InvalidParameterValueException("String_Node_Str" + Vlan.UNTAGGED + "String_Node_Str"+ "String_Node_Str"+ NetworkType.Basic);
      }
    }
  }
 else   if (zone.getNetworkType() == NetworkType.Advanced) {
    if (zone.isSecurityGroupEnabled()) {
      if (ipv6) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (ntwkOff.getGuestType() != GuestType.Shared) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(),Service.SourceNat)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(),Service.SecurityGroup)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
    if (ntwkOff.getElasticIp() || ntwkOff.getElasticLb()) {
      throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic);
    }
  }
  boolean vlanSpecified=(vlanId != null);
  if (vlanSpecified != ntwkOff.getSpecifyVlan()) {
    if (vlanSpecified) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  if (vlanId != null) {
    String uri="String_Node_Str" + vlanId;
    if (ntwkOff.getGuestType() == GuestType.Isolated) {
      if (_networksDao.countByZoneAndUri(zoneId,uri) > 0) {
        throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ zoneId);
      }
    }
 else {
      if (_networksDao.countByZoneUriAndGuestType(zoneId,uri,GuestType.Isolated) > 0) {
        throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ "String_Node_Str"+ zoneId);
      }
    }
  }
  if (_networkModel.areServicesSupportedByNetworkOffering(networkOfferingId,Service.Dns)) {
    Map<Network.Capability,String> dnsCapabilities=_networkModel.getNetworkOfferingServiceCapabilities(_configMgr.getNetworkOffering(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) {
        if (aclType == ACLType.Domain) {
          networkDomain=_networkModel.getDomainNetworkDomain(domainId,zoneId);
        }
 else         if (aclType == ACLType.Account) {
          networkDomain=_networkModel.getAccountNetworkDomain(owner.getId(),zoneId);
        }
        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" + "String_Node_Str");
        }
      }
    }
  }
  boolean cidrRequired=zone.getNetworkType() == NetworkType.Advanced && ntwkOff.getTrafficType() == TrafficType.Guest && (ntwkOff.getGuestType() == GuestType.Shared || (ntwkOff.getGuestType() == GuestType.Isolated && !_networkModel.areServicesSupportedByNetworkOffering(ntwkOff.getId(),Service.SourceNat)));
  if (cidr == null && ip6Cidr == null && cidrRequired) {
    throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str" + Network.GuestType.Shared + "String_Node_Str"+ GuestType.Isolated+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
  }
  if (zone.getNetworkType() == NetworkType.Basic && cidr != null) {
    throw new InvalidParameterValueException("String_Node_Str" + NetworkType.Basic);
  }
  if (cidr != null && ntwkOff.getGuestType() == Network.GuestType.Isolated && ntwkOff.getTrafficType() == TrafficType.Guest) {
    if (!NetUtils.validateGuestCidr(cidr)) {
      throw new InvalidParameterValueException("String_Node_Str" + cidr + "String_Node_Str");
    }
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  Long physicalNetworkId=null;
  if (pNtwk != null) {
    physicalNetworkId=pNtwk.getId();
  }
  DataCenterDeployment plan=new DataCenterDeployment(zoneId,null,null,null,null,physicalNetworkId);
  NetworkVO userNetwork=new NetworkVO();
  userNetwork.setNetworkDomain(networkDomain);
  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);
      }
    }
  }
  if (ip6Cidr != null && ip6Gateway != null) {
    userNetwork.setIp6Cidr(ip6Cidr);
    userNetwork.setIp6Gateway(ip6Gateway);
    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,ntwkOff,userNetwork,plan,name,displayText,true,domainId,aclType,subdomainAccess,vpcId);
  Network network=null;
  if (networks == null || networks.isEmpty()) {
    throw new CloudRuntimeException("String_Node_Str");
  }
 else {
    if (networks.size() > 0 && networks.get(0).getGuestType() == Network.GuestType.Isolated && 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);
    }
  }
  if (updateResourceCount) {
    _resourceLimitMgr.incrementResourceCount(owner.getId(),ResourceType.network);
  }
  txn.commit();
  UserContext.current().setEventDetails("String_Node_Str" + network.getId());
  return network;
}