Program: 105615
Project: 105615
Buggy source:
@Override @DB public Network createPrivateNetwork(final String networkName,final String displayText,long physicalNetworkId,String broadcastUriString,final String startIp,String endIp,final String gateway,String netmask,final long networkOwnerId,final Long vpcId,final Boolean sourceNat,final Long networkOfferingId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
  final Account owner=_accountMgr.getAccount(networkOwnerId);
  NetworkOfferingVO ntwkOff=null;
  if (networkOfferingId != null) {
    ntwkOff=_networkOfferingDao.findById(networkOfferingId);
  }
  if (ntwkOff == null) {
    ntwkOff=findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
  }
  final PhysicalNetwork pNtwk=_physicalNetworkDao.findById(physicalNetworkId);
  if (pNtwk == null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    ex.addProxyObject(String.valueOf(physicalNetworkId),"String_Node_Str");
    throw ex;
  }
  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 (!NetUtils.isValidIp(gateway)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!NetUtils.isValidNetmask(netmask)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  final String cidr=NetUtils.ipAndNetMaskToCidr(gateway,netmask);
  URI uri=BroadcastDomainType.fromString(broadcastUriString);
  final String uriString=uri.toString();
  BroadcastDomainType tiep=BroadcastDomainType.getSchemeValue(uri);
  if (!(tiep == BroadcastDomainType.Vlan || tiep == BroadcastDomainType.Lswitch)) {
    throw new InvalidParameterValueException("String_Node_Str" + broadcastUriString);
  }
  final NetworkOfferingVO ntwkOffFinal=ntwkOff;
  try {
    return Transaction.execute(new TransactionCallbackWithException<Network,Exception>(){
      @Override public Network doInTransaction(      TransactionStatus status) throws ResourceAllocationException, InsufficientCapacityException {
        DataCenterVO dc=_dcDao.lockRow(pNtwk.getDataCenterId(),true);
        Network privateNetwork=_networksDao.getPrivateNetwork(uriString,cidr,networkOwnerId,pNtwk.getDataCenterId(),networkOfferingId);
        if (privateNetwork == null) {
          privateNetwork=_networkMgr.createGuestNetwork(ntwkOffFinal.getId(),networkName,displayText,gateway,cidr,uriString,null,owner,null,pNtwk,pNtwk.getDataCenterId(),ACLType.Account,null,vpcId,null,null,true,null);
          if (privateNetwork != null) {
            s_logger.debug("String_Node_Str" + privateNetwork);
          }
 else {
            throw new CloudRuntimeException("String_Node_Str");
          }
        }
 else {
          s_logger.debug("String_Node_Str" + privateNetwork);
          if (vpcId != null && vpcId.equals(privateNetwork.getVpcId())) {
            throw new InvalidParameterValueException("String_Node_Str" + uriString + "String_Node_Str"+ cidr+ "String_Node_Str"+ "String_Node_Str"+ vpcId+ "String_Node_Str"+ _entityMgr.findById(DataCenter.class,pNtwk.getDataCenterId()).getName());
          }
        }
        PrivateIpVO privateIp=_privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(),startIp,vpcId);
        if (privateIp != null) {
          throw new InvalidParameterValueException("String_Node_Str" + startIp + "String_Node_Str"+ "String_Node_Str"+ _entityMgr.findById(DataCenter.class,pNtwk.getDataCenterId()).getName());
        }
        Long mac=dc.getMacAddress();
        Long nextMac=mac + 1;
        dc.setMacAddress(nextMac);
        privateIp=new PrivateIpVO(startIp,privateNetwork.getId(),nextMac,vpcId,sourceNat);
        _privateIpDao.persist(privateIp);
        _dcDao.update(dc.getId(),dc);
        s_logger.debug("String_Node_Str" + privateNetwork + "String_Node_Str");
        return privateNetwork;
      }
    }
);
  }
 catch (  Exception e) {
    ExceptionUtil.rethrowRuntime(e);
    ExceptionUtil.rethrow(e,ResourceAllocationException.class);
    ExceptionUtil.rethrow(e,InsufficientCapacityException.class);
    throw new IllegalStateException(e);
  }
}

Fixed version (ground truth):
@Override @DB public Network createPrivateNetwork(final String networkName,final String displayText,long physicalNetworkId,String broadcastUriString,final String startIp,String endIp,final String gateway,String netmask,final long networkOwnerId,final Long vpcId,final Boolean sourceNat,final Long networkOfferingId) throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
  final Account owner=_accountMgr.getAccount(networkOwnerId);
  NetworkOfferingVO ntwkOff=null;
  if (networkOfferingId != null) {
    ntwkOff=_networkOfferingDao.findById(networkOfferingId);
  }
  if (ntwkOff == null) {
    ntwkOff=findSystemNetworkOffering(NetworkOffering.SystemPrivateGatewayNetworkOffering);
  }
  final PhysicalNetwork pNtwk=_physicalNetworkDao.findById(physicalNetworkId);
  if (pNtwk == null) {
    InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    ex.addProxyObject(String.valueOf(physicalNetworkId),"String_Node_Str");
    throw ex;
  }
  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 (!NetUtils.isValidIp(gateway)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!NetUtils.isValidNetmask(netmask)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  final String cidr=NetUtils.ipAndNetMaskToCidr(gateway,netmask);
  URI uri=BroadcastDomainType.fromString(broadcastUriString);
  final String uriString=uri.toString();
  BroadcastDomainType tiep=BroadcastDomainType.getSchemeValue(uri);
  if (!(tiep == BroadcastDomainType.Vlan || tiep == BroadcastDomainType.Lswitch)) {
    throw new InvalidParameterValueException("String_Node_Str" + broadcastUriString);
  }
  final NetworkOfferingVO ntwkOffFinal=ntwkOff;
  try {
    return Transaction.execute(new TransactionCallbackWithException<Network,Exception>(){
      @Override public Network doInTransaction(      TransactionStatus status) throws ResourceAllocationException, InsufficientCapacityException {
        DataCenterVO dc=_dcDao.lockRow(pNtwk.getDataCenterId(),true);
        Network privateNetwork=_networksDao.getPrivateNetwork(uriString,cidr,networkOwnerId,pNtwk.getDataCenterId(),networkOfferingId);
        if (privateNetwork == null) {
          privateNetwork=_networkMgr.createGuestNetwork(ntwkOffFinal.getId(),networkName,displayText,gateway,cidr,uriString,null,owner,null,pNtwk,pNtwk.getDataCenterId(),ACLType.Account,null,vpcId,null,null,true,null);
          if (privateNetwork != null) {
            s_logger.debug("String_Node_Str" + privateNetwork);
          }
 else {
            throw new CloudRuntimeException("String_Node_Str");
          }
        }
 else {
          s_logger.debug("String_Node_Str" + privateNetwork);
          if (vpcId != null && vpcId.equals(privateNetwork.getVpcId())) {
            throw new InvalidParameterValueException("String_Node_Str" + uriString + "String_Node_Str"+ cidr+ "String_Node_Str"+ "String_Node_Str"+ vpcId+ "String_Node_Str"+ _entityMgr.findById(DataCenter.class,pNtwk.getDataCenterId()).getName());
          }
        }
        if (vpcId != null) {
          PrivateIpVO privateIp=_privateIpDao.findByIpAndSourceNetworkIdAndVpcId(privateNetwork.getId(),startIp,vpcId);
          if (privateIp != null) {
            throw new InvalidParameterValueException("String_Node_Str" + startIp + "String_Node_Str"+ "String_Node_Str"+ _entityMgr.findById(DataCenter.class,pNtwk.getDataCenterId()).getName());
          }
          Long mac=dc.getMacAddress();
          Long nextMac=mac + 1;
          dc.setMacAddress(nextMac);
          privateIp=new PrivateIpVO(startIp,privateNetwork.getId(),nextMac,vpcId,sourceNat);
          _privateIpDao.persist(privateIp);
          _dcDao.update(dc.getId(),dc);
        }
        s_logger.debug("String_Node_Str" + privateNetwork + "String_Node_Str");
        return privateNetwork;
      }
    }
);
  }
 catch (  Exception e) {
    ExceptionUtil.rethrowRuntime(e);
    ExceptionUtil.rethrow(e,ResourceAllocationException.class);
    ExceptionUtil.rethrow(e,InsufficientCapacityException.class);
    throw new IllegalStateException(e);
  }
}