Program: 107466
Project: 107466
Buggy source:
@Override public VlanVO createVlanAndPublicIpRange(long userId,VlanType vlanType,Long zoneId,Long accountId,Long podId,String vlanId,String vlanGateway,String vlanNetmask,String startIP,String endIP) throws InvalidParameterValueException, InternalErrorException {
  String hypervisorType=_configDao.getValue("String_Node_Str");
  if (hypervisorType.equalsIgnoreCase("String_Node_Str")) {
    if (vlanType.toString().equalsIgnoreCase("String_Node_Str") && vlanId.equalsIgnoreCase("String_Node_Str")) {
      if (_configDao.getValue("String_Node_Str") == null || _configDao.getValue("String_Node_Str").equals("String_Node_Str")) {
        throw new InternalErrorException("String_Node_Str");
      }
    }
  }
  if (!vlanId.equals(Vlan.UNTAGGED)) {
    VlanVO vlanHandle=_vlanDao.findByZoneAndVlanId(zoneId,vlanId);
    if (vlanHandle != null && !vlanHandle.getVlanType().equals(vlanType))     throw new InvalidParameterValueException("String_Node_Str" + vlanHandle.getVlanType().toString() + "String_Node_Str"+ vlanType.toString());
  }
  DataCenterVO zone;
  if (zoneId == null || ((zone=_zoneDao.findById(zoneId)) == null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (vlanType.equals(VlanType.VirtualNetwork)) {
    if (!(accountId == null && podId == null) && false) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else   if (vlanType.equals(VlanType.DirectAttached)) {
    if (!((accountId != null && podId == null) || (accountId == null && podId != null))) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (accountId != null) {
      if (vlanId.equals(Vlan.UNTAGGED)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      AccountVO account;
      if ((account=_accountDao.findById(accountId)) == null) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      List<HostPodVO> podsInZone=_podDao.listByDataCenterId(zone.getId());
      for (      HostPodVO pod : podsInZone) {
        if (_podVlanMapDao.listPodVlanMapsByPod(pod.getId()).size() > 0) {
          throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
        }
      }
      List<AccountVlanMapVO> accountVlanMaps=_accountVlanMapDao.listAccountVlanMapsByAccount(accountId);
      for (      AccountVlanMapVO accountVlanMap : accountVlanMaps) {
        VlanVO vlan=_vlanDao.findById(accountVlanMap.getVlanDbId());
        if (vlan.getDataCenterId() == zone.getId()) {
          throw new InvalidParameterValueException("String_Node_Str" + account.getAccountName() + "String_Node_Str"+ zone.getName()+ "String_Node_Str");
        }
      }
    }
 else     if (podId != null) {
      if (!vlanId.equals(Vlan.UNTAGGED)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      HostPodVO pod=null;
      if (podId != null && ((pod=_podDao.findById(podId)) == null)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      List<AccountVlanMapVO> accountVlanMaps=_accountVlanMapDao.listAllIncludingRemoved();
      for (      AccountVlanMapVO accountVlanMap : accountVlanMaps) {
        VlanVO vlan=_vlanDao.findById(accountVlanMap.getVlanDbId());
        if (vlan.getDataCenterId() == zone.getId()) {
          throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
        }
      }
    }
  }
 else {
    throw new InvalidParameterValueException("String_Node_Str" + VlanType.values().toString());
  }
  if (!NetUtils.isValidIp(vlanGateway)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!NetUtils.isValidIp(vlanNetmask)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  String newVlanSubnet=NetUtils.getSubNet(vlanGateway,vlanNetmask);
  String guestNetworkCidr=zone.getGuestNetworkCidr();
  String[] cidrPair=guestNetworkCidr.split("String_Node_Str");
  String guestIpNetwork=NetUtils.getIpRangeStartIpFromCidr(cidrPair[0],Long.parseLong(cidrPair[1]));
  long guestCidrSize=Long.parseLong(cidrPair[1]);
  long vlanCidrSize=NetUtils.getCidrSize(vlanNetmask);
  long cidrSizeToUse=-1;
  if (vlanCidrSize < guestCidrSize) {
    cidrSizeToUse=vlanCidrSize;
  }
 else {
    cidrSizeToUse=guestCidrSize;
  }
  String guestSubnet=NetUtils.getCidrSubNet(guestIpNetwork,cidrSizeToUse);
  if (newVlanSubnet.equals(guestSubnet)) {
    throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
  }
  checkPublicIpRangeErrors(zoneId,vlanId,vlanGateway,vlanNetmask,startIP,endIP);
  List<VlanVO> vlans=_vlanDao.findByZone(zone.getId());
  for (  VlanVO vlan : vlans) {
    String otherVlanGateway=vlan.getVlanGateway();
    String otherVlanSubnet=NetUtils.getSubNet(vlan.getVlanGateway(),vlan.getVlanNetmask());
    String[] otherVlanIpRange=vlan.getIpRange().split("String_Node_Str");
    String otherVlanStartIP=otherVlanIpRange[0];
    String otherVlanEndIP=null;
    if (otherVlanIpRange.length > 1) {
      otherVlanEndIP=otherVlanIpRange[1];
    }
    if (!vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
      throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str"+ zone.getName()+ "String_Node_Str");
    }
    if (vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
      if (NetUtils.ipRangesOverlap(startIP,endIP,otherVlanStartIP,otherVlanEndIP)) {
        throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str");
      }
      if (!vlanGateway.equals(otherVlanGateway)) {
        throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str"+ otherVlanGateway+ "String_Node_Str");
      }
    }
  }
  if (_zoneDao.findVnet(zoneId,vlanId).size() > 0) {
    throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ zone.getName());
  }
  String ipRange=startIP;
  if (endIP != null) {
    ipRange+="String_Node_Str" + endIP;
  }
  VlanVO vlan=new VlanVO(vlanType,vlanId,vlanGateway,vlanNetmask,zone.getId(),ipRange);
  vlan=_vlanDao.persist(vlan);
  if (accountId != null && vlanType.equals(VlanType.VirtualNetwork)) {
    if (!savePublicIPRangeForAccount(startIP,endIP,zoneId,vlan.getId(),accountId,_accountDao.findById(accountId).getDomainId())) {
      deletePublicIPRange(vlan.getId());
      _vlanDao.expunge(vlan.getId());
      throw new InternalErrorException("String_Node_Str");
    }
  }
 else   if (!savePublicIPRange(startIP,endIP,zoneId,vlan.getId())) {
    deletePublicIPRange(vlan.getId());
    _vlanDao.expunge(vlan.getId());
    throw new InternalErrorException("String_Node_Str");
  }
  if (accountId != null) {
    AccountVlanMapVO accountVlanMapVO=new AccountVlanMapVO(accountId,vlan.getId());
    _accountVlanMapDao.persist(accountVlanMapVO);
  }
 else   if (podId != null) {
    PodVlanMapVO podVlanMapVO=new PodVlanMapVO(podId,vlan.getId());
    _podVlanMapDao.persist(podVlanMapVO);
  }
  String eventMsg="String_Node_Str" + vlanId + "String_Node_Str"+ vlanGateway+ "String_Node_Str"+ vlanNetmask+ "String_Node_Str"+ startIP;
  if (endIP != null) {
    eventMsg+="String_Node_Str" + endIP;
  }
  eventMsg+="String_Node_Str";
  saveConfigurationEvent(userId,accountId,EventTypes.EVENT_VLAN_IP_RANGE_CREATE,eventMsg,"String_Node_Str" + vlanType,"String_Node_Str" + zoneId,"String_Node_Str" + accountId,"String_Node_Str" + podId,"String_Node_Str" + vlanId,"String_Node_Str" + vlanGateway,"String_Node_Str" + vlanNetmask,"String_Node_Str" + startIP,"String_Node_Str" + endIP);
  return vlan;
}

Fixed version (ground truth):
@Override public VlanVO createVlanAndPublicIpRange(long userId,VlanType vlanType,Long zoneId,Long accountId,Long podId,String vlanId,String vlanGateway,String vlanNetmask,String startIP,String endIP) throws InvalidParameterValueException, InternalErrorException {
  String hypervisorType=_configDao.getValue("String_Node_Str");
  if (hypervisorType.equalsIgnoreCase("String_Node_Str")) {
    if (vlanType.toString().equalsIgnoreCase("String_Node_Str") && vlanId.equalsIgnoreCase("String_Node_Str")) {
      if (_configDao.getValue("String_Node_Str") == null || _configDao.getValue("String_Node_Str").equals("String_Node_Str")) {
        throw new InternalErrorException("String_Node_Str");
      }
    }
  }
  if (!vlanId.equals(Vlan.UNTAGGED)) {
    VlanVO vlanHandle=_vlanDao.findByZoneAndVlanId(zoneId,vlanId);
    if (vlanHandle != null && !vlanHandle.getVlanType().equals(vlanType))     throw new InvalidParameterValueException("String_Node_Str" + vlanHandle.getVlanType().toString() + "String_Node_Str"+ vlanType.toString());
  }
  DataCenterVO zone;
  if (zoneId == null || ((zone=_zoneDao.findById(zoneId)) == null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (vlanType.equals(VlanType.VirtualNetwork)) {
    if (!(accountId == null && podId == null) && false) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else   if (vlanType.equals(VlanType.DirectAttached)) {
    if (!((accountId != null && podId == null) || (accountId == null && podId != null))) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (accountId != null) {
      if (vlanId.equals(Vlan.UNTAGGED)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      AccountVO account;
      if ((account=_accountDao.findById(accountId)) == null) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      List<HostPodVO> podsInZone=_podDao.listByDataCenterId(zone.getId());
      for (      HostPodVO pod : podsInZone) {
        if (_podVlanMapDao.listPodVlanMapsByPod(pod.getId()).size() > 0) {
          throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
        }
      }
    }
 else     if (podId != null) {
      if (!vlanId.equals(Vlan.UNTAGGED)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      HostPodVO pod=null;
      if (podId != null && ((pod=_podDao.findById(podId)) == null)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      List<AccountVlanMapVO> accountVlanMaps=_accountVlanMapDao.listAllIncludingRemoved();
      for (      AccountVlanMapVO accountVlanMap : accountVlanMaps) {
        VlanVO vlan=_vlanDao.findById(accountVlanMap.getVlanDbId());
        if (vlan.getDataCenterId() == zone.getId()) {
          throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
        }
      }
    }
  }
 else {
    throw new InvalidParameterValueException("String_Node_Str" + VlanType.values().toString());
  }
  if (!NetUtils.isValidIp(vlanGateway)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!NetUtils.isValidIp(vlanNetmask)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  String newVlanSubnet=NetUtils.getSubNet(vlanGateway,vlanNetmask);
  String guestNetworkCidr=zone.getGuestNetworkCidr();
  String[] cidrPair=guestNetworkCidr.split("String_Node_Str");
  String guestIpNetwork=NetUtils.getIpRangeStartIpFromCidr(cidrPair[0],Long.parseLong(cidrPair[1]));
  long guestCidrSize=Long.parseLong(cidrPair[1]);
  long vlanCidrSize=NetUtils.getCidrSize(vlanNetmask);
  long cidrSizeToUse=-1;
  if (vlanCidrSize < guestCidrSize) {
    cidrSizeToUse=vlanCidrSize;
  }
 else {
    cidrSizeToUse=guestCidrSize;
  }
  String guestSubnet=NetUtils.getCidrSubNet(guestIpNetwork,cidrSizeToUse);
  if (newVlanSubnet.equals(guestSubnet)) {
    throw new InvalidParameterValueException("String_Node_Str" + zone.getName() + "String_Node_Str");
  }
  checkPublicIpRangeErrors(zoneId,vlanId,vlanGateway,vlanNetmask,startIP,endIP);
  List<VlanVO> vlans=_vlanDao.findByZone(zone.getId());
  for (  VlanVO vlan : vlans) {
    String otherVlanGateway=vlan.getVlanGateway();
    String otherVlanSubnet=NetUtils.getSubNet(vlan.getVlanGateway(),vlan.getVlanNetmask());
    String[] otherVlanIpRange=vlan.getIpRange().split("String_Node_Str");
    String otherVlanStartIP=otherVlanIpRange[0];
    String otherVlanEndIP=null;
    if (otherVlanIpRange.length > 1) {
      otherVlanEndIP=otherVlanIpRange[1];
    }
    if (!vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
      throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str"+ zone.getName()+ "String_Node_Str");
    }
    if (vlanId.equals(vlan.getVlanId()) && newVlanSubnet.equals(otherVlanSubnet)) {
      if (NetUtils.ipRangesOverlap(startIP,endIP,otherVlanStartIP,otherVlanEndIP)) {
        throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str");
      }
      if (!vlanGateway.equals(otherVlanGateway)) {
        throw new InvalidParameterValueException("String_Node_Str" + vlan.getVlanId() + "String_Node_Str"+ otherVlanGateway+ "String_Node_Str");
      }
    }
  }
  if (_zoneDao.findVnet(zoneId,vlanId).size() > 0) {
    throw new InvalidParameterValueException("String_Node_Str" + vlanId + "String_Node_Str"+ zone.getName());
  }
  String ipRange=startIP;
  if (endIP != null) {
    ipRange+="String_Node_Str" + endIP;
  }
  VlanVO vlan=new VlanVO(vlanType,vlanId,vlanGateway,vlanNetmask,zone.getId(),ipRange);
  vlan=_vlanDao.persist(vlan);
  if (accountId != null && vlanType.equals(VlanType.VirtualNetwork)) {
    if (!savePublicIPRangeForAccount(startIP,endIP,zoneId,vlan.getId(),accountId,_accountDao.findById(accountId).getDomainId())) {
      deletePublicIPRange(vlan.getId());
      _vlanDao.expunge(vlan.getId());
      throw new InternalErrorException("String_Node_Str");
    }
  }
 else   if (!savePublicIPRange(startIP,endIP,zoneId,vlan.getId())) {
    deletePublicIPRange(vlan.getId());
    _vlanDao.expunge(vlan.getId());
    throw new InternalErrorException("String_Node_Str");
  }
  if (accountId != null) {
    AccountVlanMapVO accountVlanMapVO=new AccountVlanMapVO(accountId,vlan.getId());
    _accountVlanMapDao.persist(accountVlanMapVO);
  }
 else   if (podId != null) {
    PodVlanMapVO podVlanMapVO=new PodVlanMapVO(podId,vlan.getId());
    _podVlanMapDao.persist(podVlanMapVO);
  }
  String eventMsg="String_Node_Str" + vlanId + "String_Node_Str"+ vlanGateway+ "String_Node_Str"+ vlanNetmask+ "String_Node_Str"+ startIP;
  if (endIP != null) {
    eventMsg+="String_Node_Str" + endIP;
  }
  eventMsg+="String_Node_Str";
  saveConfigurationEvent(userId,accountId,EventTypes.EVENT_VLAN_IP_RANGE_CREATE,eventMsg,"String_Node_Str" + vlanType,"String_Node_Str" + zoneId,"String_Node_Str" + accountId,"String_Node_Str" + podId,"String_Node_Str" + vlanId,"String_Node_Str" + vlanGateway,"String_Node_Str" + vlanNetmask,"String_Node_Str" + startIP,"String_Node_Str" + endIP);
  return vlan;
}