Program: 89206
Project: 89206
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_NETWORK_CREATE,eventDescription="String_Node_Str") public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException {
  Long networkOfferingId=cmd.getNetworkOfferingId();
  String gateway=cmd.getGateway();
  String startIP=cmd.getStartIp();
  String endIP=cmd.getEndIp();
  String netmask=cmd.getNetmask();
  String networkDomain=cmd.getNetworkDomain();
  String vlanId=cmd.getVlan();
  String name=cmd.getNetworkName();
  String displayText=cmd.getDisplayText();
  Long userId=UserContext.current().getCallerUserId();
  Account caller=UserContext.current().getCaller();
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  Long zoneId=cmd.getZoneId();
  String aclTypeStr=cmd.getAclType();
  Long domainId=cmd.getDomainId();
  boolean isDomainSpecific=false;
  Boolean subdomainAccess=cmd.getSubdomainAccess();
  NetworkOfferingVO networkOffering=_networkOfferingDao.findById(networkOfferingId);
  if (networkOffering == null || networkOffering.isSystemOnly()) {
    throw new InvalidParameterValueException("String_Node_Str" + networkOfferingId);
  }
  PhysicalNetwork pNtwk=null;
  if (physicalNetworkId != null) {
    pNtwk=_physicalNetworkDao.findById(physicalNetworkId);
    if (pNtwk == null) {
      throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
    }
  }
  if (zoneId == null) {
    zoneId=pNtwk.getDataCenterId();
  }
  DataCenter zone=_dcDao.findById(zoneId);
  if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
    throw new PermissionDeniedException("String_Node_Str" + zone.getId());
  }
  ACLType aclType=null;
  if (aclTypeStr != null) {
    if (aclTypeStr.equalsIgnoreCase(ACLType.Account.toString())) {
      aclType=ACLType.Account;
    }
 else     if (aclTypeStr.equalsIgnoreCase(ACLType.Domain.toString())) {
      aclType=ACLType.Domain;
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (networkOffering.getGuestType() == GuestType.Isolated) {
      if (aclType != ACLType.Account) {
        throw new InvalidParameterValueException("String_Node_Str" + ACLType.Account + "String_Node_Str"+ Network.GuestType.Isolated);
      }
    }
 else     if (networkOffering.getGuestType() == GuestType.Shared) {
      if (aclType != ACLType.Domain) {
        throw new InvalidParameterValueException("String_Node_Str" + ACLType.Domain + "String_Node_Str"+ Network.GuestType.Shared);
      }
    }
  }
 else {
    if (networkOffering.getGuestType() == GuestType.Isolated) {
      aclType=ACLType.Account;
    }
 else     if (networkOffering.getGuestType() == GuestType.Shared) {
      aclType=ACLType.Domain;
    }
  }
  if (aclType == ACLType.Domain) {
    if (!_accountMgr.isAdmin(caller.getType())) {
      throw new PermissionDeniedException("String_Node_Str");
    }
    if (networkOffering.getGuestType() != GuestType.Shared) {
      throw new InvalidParameterValueException("String_Node_Str" + GuestType.Shared + "String_Node_Str"+ ACLType.Domain);
    }
    if (domainId != null) {
      if (networkOffering.getTrafficType() != TrafficType.Guest || networkOffering.getGuestType() != Network.GuestType.Shared) {
        throw new InvalidParameterValueException("String_Node_Str" + TrafficType.Guest + "String_Node_Str"+ Network.GuestType.Shared);
      }
      DomainVO domain=_domainDao.findById(domainId);
      if (domain == null) {
        throw new InvalidParameterValueException("String_Node_Str" + domainId);
      }
      _accountMgr.checkAccess(caller,domain);
    }
    isDomainSpecific=true;
  }
 else   if (subdomainAccess != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Account owner=null;
  if ((cmd.getAccountName() != null && domainId != null) || cmd.getProjectId() != null) {
    owner=_accountMgr.finalizeOwner(caller,cmd.getAccountName(),domainId,cmd.getProjectId());
  }
 else {
    owner=caller;
  }
  UserContext.current().setAccountId(owner.getAccountId());
  if (startIP != null) {
    if (!NetUtils.isValidIp(startIP)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (endIP == null) {
      endIP=startIP;
    }
 else     if (!NetUtils.isValidIp(endIP)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  if (startIP != null && endIP != null) {
    if (!(gateway != null && netmask != null)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  String cidr=null;
  if (gateway != null && netmask != null) {
    if (!NetUtils.isValidIp(gateway)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (!NetUtils.isValidNetmask(netmask)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    cidr=NetUtils.ipAndNetMaskToCidr(gateway,netmask);
  }
  if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (networkOffering.getTrafficType() != TrafficType.Guest || networkOffering.getGuestType() != Network.GuestType.Isolated && areServicesSupportedByNetworkOffering(networkOffering.getId(),Service.SourceNat))) {
    throw new InvalidParameterValueException("String_Node_Str" + TrafficType.Guest + "String_Node_Str"+ Network.GuestType.Isolated+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
  }
  if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (cidr != null || vlanId != null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
    String[] cidrPair=cidr.split("String_Node_Str");
    int cidrSize=Integer.valueOf(cidrPair[1]);
    if (cidrSize < _cidrLimit) {
      throw new InvalidParameterValueException("String_Node_Str" + _cidrLimit);
    }
  }
  if (cidr != null && networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  checkVirtualNetworkCidrOverlap(zoneId,cidr);
  Transaction txn=Transaction.currentTxn();
  txn.start();
  Long sharedDomainId=null;
  if (isDomainSpecific) {
    if (domainId != null) {
      sharedDomainId=domainId;
    }
 else {
      sharedDomainId=_domainMgr.getDomain(Domain.ROOT_DOMAIN).getId();
      subdomainAccess=true;
    }
  }
  if (aclType == ACLType.Domain) {
    owner=_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
  }
  Network network=createGuestNetwork(networkOfferingId,name,displayText,gateway,cidr,vlanId,networkDomain,owner,false,sharedDomainId,pNtwk,zoneId,aclType,subdomainAccess);
  boolean createVlan=(startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && ((network.getGuestType() == Network.GuestType.Shared) || (network.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(),Service.SourceNat))));
  if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
    _configMgr.createVlanAndPublicIpRange(userId,pNtwk.getDataCenterId(),null,startIP,endIP,gateway,netmask,false,vlanId,null,network.getId(),physicalNetworkId);
  }
  txn.commit();
  return network;
}

Fixed version (ground truth):
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_NETWORK_CREATE,eventDescription="String_Node_Str") public Network createNetwork(CreateNetworkCmd cmd) throws InsufficientCapacityException, ConcurrentOperationException {
  Long networkOfferingId=cmd.getNetworkOfferingId();
  String gateway=cmd.getGateway();
  String startIP=cmd.getStartIp();
  String endIP=cmd.getEndIp();
  String netmask=cmd.getNetmask();
  String networkDomain=cmd.getNetworkDomain();
  String vlanId=cmd.getVlan();
  String name=cmd.getNetworkName();
  String displayText=cmd.getDisplayText();
  Long userId=UserContext.current().getCallerUserId();
  Account caller=UserContext.current().getCaller();
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  Long zoneId=cmd.getZoneId();
  String aclTypeStr=cmd.getAclType();
  Long domainId=cmd.getDomainId();
  boolean isDomainSpecific=false;
  Boolean subdomainAccess=cmd.getSubdomainAccess();
  NetworkOfferingVO networkOffering=_networkOfferingDao.findById(networkOfferingId);
  if (networkOffering == null || networkOffering.isSystemOnly()) {
    throw new InvalidParameterValueException("String_Node_Str" + networkOfferingId);
  }
  PhysicalNetwork pNtwk=null;
  if (physicalNetworkId != null) {
    pNtwk=_physicalNetworkDao.findById(physicalNetworkId);
    if (pNtwk == null) {
      throw new InvalidParameterValueException("String_Node_Str" + physicalNetworkId);
    }
  }
  if (zoneId == null) {
    zoneId=pNtwk.getDataCenterId();
  }
  DataCenter zone=_dcDao.findById(zoneId);
  if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
    throw new PermissionDeniedException("String_Node_Str" + zone.getId());
  }
  ACLType aclType=null;
  if (aclTypeStr != null) {
    if (aclTypeStr.equalsIgnoreCase(ACLType.Account.toString())) {
      aclType=ACLType.Account;
    }
 else     if (aclTypeStr.equalsIgnoreCase(ACLType.Domain.toString())) {
      aclType=ACLType.Domain;
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (networkOffering.getGuestType() == GuestType.Isolated) {
      if (aclType != ACLType.Account) {
        throw new InvalidParameterValueException("String_Node_Str" + ACLType.Account + "String_Node_Str"+ Network.GuestType.Isolated);
      }
    }
 else     if (networkOffering.getGuestType() == GuestType.Shared) {
      if (aclType != ACLType.Domain) {
        throw new InvalidParameterValueException("String_Node_Str" + ACLType.Domain + "String_Node_Str"+ Network.GuestType.Shared);
      }
    }
  }
 else {
    if (networkOffering.getGuestType() == GuestType.Isolated) {
      aclType=ACLType.Account;
    }
 else     if (networkOffering.getGuestType() == GuestType.Shared) {
      aclType=ACLType.Domain;
    }
  }
  if (aclType == ACLType.Domain) {
    if (!_accountMgr.isAdmin(caller.getType())) {
      throw new PermissionDeniedException("String_Node_Str");
    }
    if (networkOffering.getGuestType() != GuestType.Shared) {
      throw new InvalidParameterValueException("String_Node_Str" + GuestType.Shared + "String_Node_Str"+ ACLType.Domain);
    }
    if (domainId != null) {
      if (networkOffering.getTrafficType() != TrafficType.Guest || networkOffering.getGuestType() != Network.GuestType.Shared) {
        throw new InvalidParameterValueException("String_Node_Str" + TrafficType.Guest + "String_Node_Str"+ Network.GuestType.Shared);
      }
      DomainVO domain=_domainDao.findById(domainId);
      if (domain == null) {
        throw new InvalidParameterValueException("String_Node_Str" + domainId);
      }
      _accountMgr.checkAccess(caller,domain);
    }
    isDomainSpecific=true;
  }
 else   if (subdomainAccess != null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Account owner=null;
  if ((cmd.getAccountName() != null && domainId != null) || cmd.getProjectId() != null) {
    owner=_accountMgr.finalizeOwner(caller,cmd.getAccountName(),domainId,cmd.getProjectId());
  }
 else {
    owner=caller;
  }
  UserContext.current().setAccountId(owner.getAccountId());
  if (startIP != null) {
    if (!NetUtils.isValidIp(startIP)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (endIP == null) {
      endIP=startIP;
    }
 else     if (!NetUtils.isValidIp(endIP)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  if (startIP != null && endIP != null) {
    if (!(gateway != null && netmask != null)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  String cidr=null;
  if (gateway != null && netmask != null) {
    if (!NetUtils.isValidIp(gateway)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (!NetUtils.isValidNetmask(netmask)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    cidr=NetUtils.ipAndNetMaskToCidr(gateway,netmask);
  }
  if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (networkOffering.getTrafficType() != TrafficType.Guest || networkOffering.getGuestType() != Network.GuestType.Isolated && areServicesSupportedByNetworkOffering(networkOffering.getId(),Service.SourceNat))) {
    throw new InvalidParameterValueException("String_Node_Str" + TrafficType.Guest + "String_Node_Str"+ Network.GuestType.Isolated+ "String_Node_Str"+ Service.SourceNat.getName()+ "String_Node_Str");
  }
  if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL && (cidr != null || vlanId != null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && cidr != null) {
    String[] cidrPair=cidr.split("String_Node_Str");
    int cidrSize=Integer.valueOf(cidrPair[1]);
    if (cidrSize < _cidrLimit) {
      throw new InvalidParameterValueException("String_Node_Str" + _cidrLimit);
    }
  }
  if (cidr != null && networkOfferingIsConfiguredForExternalNetworking(networkOfferingId)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (cidr != null) {
    checkVirtualNetworkCidrOverlap(zoneId,cidr);
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  Long sharedDomainId=null;
  if (isDomainSpecific) {
    if (domainId != null) {
      sharedDomainId=domainId;
    }
 else {
      sharedDomainId=_domainMgr.getDomain(Domain.ROOT_DOMAIN).getId();
      subdomainAccess=true;
    }
  }
  if (aclType == ACLType.Domain) {
    owner=_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM);
  }
  Network network=createGuestNetwork(networkOfferingId,name,displayText,gateway,cidr,vlanId,networkDomain,owner,false,sharedDomainId,pNtwk,zoneId,aclType,subdomainAccess);
  boolean createVlan=(startIP != null && endIP != null && zone.getNetworkType() == NetworkType.Advanced && ((network.getGuestType() == Network.GuestType.Shared) || (network.getGuestType() == GuestType.Isolated && !areServicesSupportedByNetworkOffering(networkOffering.getId(),Service.SourceNat))));
  if (caller.getType() == Account.ACCOUNT_TYPE_ADMIN && createVlan) {
    _configMgr.createVlanAndPublicIpRange(userId,pNtwk.getDataCenterId(),null,startIP,endIP,gateway,netmask,false,vlanId,null,network.getId(),physicalNetworkId);
  }
  txn.commit();
  return network;
}