Program: 106019
Project: 106019
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_ZONE_EDIT,eventDescription="String_Node_Str",async=false) public DataCenter editZone(UpdateZoneCmd cmd){
  final Long zoneId=cmd.getId();
  String zoneName=cmd.getZoneName();
  String dns1=cmd.getDns1();
  String dns2=cmd.getDns2();
  String ip6Dns1=cmd.getIp6Dns1();
  String ip6Dns2=cmd.getIp6Dns2();
  String internalDns1=cmd.getInternalDns1();
  String internalDns2=cmd.getInternalDns2();
  String guestCidr=cmd.getGuestCidrAddress();
  List<String> dnsSearchOrder=cmd.getDnsSearchOrder();
  final Boolean isPublic=cmd.isPublic();
  final String allocationStateStr=cmd.getAllocationState();
  final String dhcpProvider=cmd.getDhcpProvider();
  Map<?,?> detailsMap=cmd.getDetails();
  String networkDomain=cmd.getDomain();
  Boolean localStorageEnabled=cmd.getLocalStorageEnabled();
  final Map<String,String> newDetails=new HashMap<String,String>();
  if (detailsMap != null) {
    Collection<?> zoneDetailsCollection=detailsMap.values();
    Iterator<?> iter=zoneDetailsCollection.iterator();
    while (iter.hasNext()) {
      HashMap<?,?> detail=(HashMap<?,?>)iter.next();
      String key=(String)detail.get("String_Node_Str");
      String value=(String)detail.get("String_Node_Str");
      if ((key == null) || (value == null)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      newDetails.put(key,value);
    }
  }
  if (dnsSearchOrder != null) {
    for (    String dom : dnsSearchOrder) {
      if (!NetUtils.verifyDomainName(dom)) {
        throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
      }
    }
    newDetails.put(ZoneConfig.DnsSearchOrder.getName(),StringUtils.join(dnsSearchOrder,"String_Node_Str"));
  }
  final DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  if (zoneName == null) {
    zoneName=zone.getName();
  }
  if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!validZone(zoneId)) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId + "String_Node_Str");
  }
  String oldZoneName=zone.getName();
  if (zoneName == null) {
    zoneName=oldZoneName;
  }
  if (dns1 == null) {
    dns1=zone.getDns1();
  }
  if (dns2 == null) {
    dns2=zone.getDns2();
  }
  if (ip6Dns1 == null) {
    ip6Dns1=zone.getIp6Dns1();
  }
  if (ip6Dns2 == null) {
    ip6Dns2=zone.getIp6Dns2();
  }
  if (internalDns1 == null) {
    internalDns1=zone.getInternalDns1();
  }
  if (internalDns2 == null) {
    internalDns2=zone.getInternalDns2();
  }
  if (guestCidr == null) {
    guestCidr=zone.getGuestNetworkCidr();
  }
  if (networkDomain != null && !networkDomain.isEmpty()) {
    if (!NetUtils.verifyDomainName(networkDomain)) {
      throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    }
  }
  boolean checkForDuplicates=!zoneName.equals(oldZoneName);
  checkZoneParameters(zoneName,dns1,dns2,internalDns1,internalDns2,checkForDuplicates,null,allocationStateStr,ip6Dns1,ip6Dns2);
  zone.setName(zoneName);
  zone.setDns1(dns1);
  zone.setDns2(dns2);
  zone.setIp6Dns1(ip6Dns1);
  zone.setIp6Dns2(ip6Dns2);
  zone.setInternalDns1(internalDns1);
  zone.setInternalDns2(internalDns2);
  zone.setGuestNetworkCidr(guestCidr);
  if (localStorageEnabled != null) {
    zone.setLocalStorageEnabled(localStorageEnabled.booleanValue());
  }
  if (networkDomain != null) {
    if (networkDomain.isEmpty()) {
      zone.setDomain(null);
    }
 else {
      zone.setDomain(networkDomain);
    }
  }
  Transaction.execute(new TransactionCallbackNoReturn(){
    @Override public void doInTransactionWithoutResult(    TransactionStatus status){
      Map<String,String> updatedDetails=new HashMap<String,String>();
      _zoneDao.loadDetails(zone);
      if (zone.getDetails() != null) {
        updatedDetails.putAll(zone.getDetails());
      }
      updatedDetails.putAll(newDetails);
      zone.setDetails(updatedDetails);
      if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        Grouping.AllocationState allocationState=Grouping.AllocationState.valueOf(allocationStateStr);
        if (allocationState == Grouping.AllocationState.Enabled) {
          try {
            PhysicalNetwork mgmtPhyNetwork;
            mgmtPhyNetwork=_networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Management);
            if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) {
              _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Public);
            }
            try {
              _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Storage);
            }
 catch (            InvalidParameterValueException noStorage) {
              PhysicalNetworkTrafficTypeVO mgmtTraffic=_trafficTypeDao.findBy(mgmtPhyNetwork.getId(),TrafficType.Management);
              _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(),TrafficType.Storage.toString(),mgmtTraffic.getXenNetworkLabel(),mgmtTraffic.getKvmNetworkLabel(),mgmtTraffic.getVmwareNetworkLabel(),mgmtTraffic.getSimulatorNetworkLabel(),mgmtTraffic.getVlan(),mgmtTraffic.getHypervNetworkLabel());
              s_logger.info("String_Node_Str" + mgmtPhyNetwork.getId() + "String_Node_Str");
            }
          }
 catch (          InvalidParameterValueException ex) {
            throw new InvalidParameterValueException("String_Node_Str" + ex.getMessage());
          }
        }
        _capacityDao.updateCapacityState(zone.getId(),null,null,null,allocationStateStr);
        zone.setAllocationState(allocationState);
      }
      if (dhcpProvider != null) {
        zone.setDhcpProvider(dhcpProvider);
      }
      if (isPublic != null && isPublic) {
        zone.setDomainId(null);
        zone.setDomain(null);
        DedicatedResourceVO resource=_dedicatedDao.findByZoneId(zoneId);
        Long resourceId=null;
        if (resource != null) {
          resourceId=resource.getId();
          if (!_dedicatedDao.remove(resourceId)) {
            throw new CloudRuntimeException("String_Node_Str" + resourceId);
          }
          List<DedicatedResourceVO> resourcesInGroup=_dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId());
          if (resourcesInGroup.isEmpty()) {
            _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(),null,null,null);
          }
        }
      }
      if (!_zoneDao.update(zoneId,zone)) {
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
  }
);
  return zone;
}

Fixed version (ground truth):
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_ZONE_EDIT,eventDescription="String_Node_Str",async=false) public DataCenter editZone(UpdateZoneCmd cmd){
  final Long zoneId=cmd.getId();
  String zoneName=cmd.getZoneName();
  String dns1=cmd.getDns1();
  String dns2=cmd.getDns2();
  String ip6Dns1=cmd.getIp6Dns1();
  String ip6Dns2=cmd.getIp6Dns2();
  String internalDns1=cmd.getInternalDns1();
  String internalDns2=cmd.getInternalDns2();
  String guestCidr=cmd.getGuestCidrAddress();
  List<String> dnsSearchOrder=cmd.getDnsSearchOrder();
  final Boolean isPublic=cmd.isPublic();
  final String allocationStateStr=cmd.getAllocationState();
  final String dhcpProvider=cmd.getDhcpProvider();
  Map<?,?> detailsMap=cmd.getDetails();
  String networkDomain=cmd.getDomain();
  Boolean localStorageEnabled=cmd.getLocalStorageEnabled();
  final Map<String,String> newDetails=new HashMap<String,String>();
  if (detailsMap != null) {
    Collection<?> zoneDetailsCollection=detailsMap.values();
    Iterator<?> iter=zoneDetailsCollection.iterator();
    while (iter.hasNext()) {
      HashMap<?,?> detail=(HashMap<?,?>)iter.next();
      String key=(String)detail.get("String_Node_Str");
      String value=(String)detail.get("String_Node_Str");
      if ((key == null) || (value == null)) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      newDetails.put(key,value);
    }
  }
  if (dnsSearchOrder != null) {
    for (    String dom : dnsSearchOrder) {
      if (!NetUtils.verifyDomainName(dom)) {
        throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
      }
    }
    newDetails.put(ZoneConfig.DnsSearchOrder.getName(),StringUtils.join(dnsSearchOrder,"String_Node_Str"));
  }
  final DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  if (zoneName == null) {
    zoneName=zone.getName();
  }
  if ((guestCidr != null) && !NetUtils.validateGuestCidr(guestCidr)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (!validZone(zoneId)) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId + "String_Node_Str");
  }
  String oldZoneName=zone.getName();
  if (zoneName == null) {
    zoneName=oldZoneName;
  }
  if (dns1 == null) {
    dns1=zone.getDns1();
  }
  if (dns2 == null) {
    dns2=zone.getDns2();
  }
  if (ip6Dns1 == null) {
    ip6Dns1=zone.getIp6Dns1();
  }
  if (ip6Dns2 == null) {
    ip6Dns2=zone.getIp6Dns2();
  }
  if (internalDns1 == null) {
    internalDns1=zone.getInternalDns1();
  }
  if (internalDns2 == null) {
    internalDns2=zone.getInternalDns2();
  }
  if (guestCidr == null) {
    guestCidr=zone.getGuestNetworkCidr();
  }
  if (networkDomain != null && !networkDomain.isEmpty()) {
    if (!NetUtils.verifyDomainName(networkDomain)) {
      throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    }
  }
  boolean checkForDuplicates=!zoneName.equals(oldZoneName);
  checkZoneParameters(zoneName,dns1,dns2,internalDns1,internalDns2,checkForDuplicates,null,allocationStateStr,ip6Dns1,ip6Dns2);
  zone.setName(zoneName);
  zone.setDns1(dns1);
  zone.setDns2(dns2);
  zone.setIp6Dns1(ip6Dns1);
  zone.setIp6Dns2(ip6Dns2);
  zone.setInternalDns1(internalDns1);
  zone.setInternalDns2(internalDns2);
  zone.setGuestNetworkCidr(guestCidr);
  if (localStorageEnabled != null) {
    zone.setLocalStorageEnabled(localStorageEnabled.booleanValue());
  }
  if (networkDomain != null) {
    if (networkDomain.isEmpty()) {
      zone.setDomain(null);
    }
 else {
      zone.setDomain(networkDomain);
    }
  }
  Transaction.execute(new TransactionCallbackNoReturn(){
    @Override public void doInTransactionWithoutResult(    TransactionStatus status){
      Map<String,String> updatedDetails=new HashMap<String,String>();
      _zoneDao.loadDetails(zone);
      if (zone.getDetails() != null) {
        updatedDetails.putAll(zone.getDetails());
      }
      updatedDetails.putAll(newDetails);
      zone.setDetails(updatedDetails);
      if (allocationStateStr != null && !allocationStateStr.isEmpty()) {
        Grouping.AllocationState allocationState=Grouping.AllocationState.valueOf(allocationStateStr);
        if (allocationState == Grouping.AllocationState.Enabled) {
          try {
            PhysicalNetwork mgmtPhyNetwork;
            mgmtPhyNetwork=_networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Management);
            if (NetworkType.Advanced == zone.getNetworkType() && !zone.isSecurityGroupEnabled()) {
              _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Public);
            }
            try {
              _networkModel.getDefaultPhysicalNetworkByZoneAndTrafficType(zoneId,TrafficType.Storage);
            }
 catch (            InvalidParameterValueException noStorage) {
              PhysicalNetworkTrafficTypeVO mgmtTraffic=_trafficTypeDao.findBy(mgmtPhyNetwork.getId(),TrafficType.Management);
              _networkSvc.addTrafficTypeToPhysicalNetwork(mgmtPhyNetwork.getId(),TrafficType.Storage.toString(),"String_Node_Str",mgmtTraffic.getXenNetworkLabel(),mgmtTraffic.getKvmNetworkLabel(),mgmtTraffic.getVmwareNetworkLabel(),mgmtTraffic.getSimulatorNetworkLabel(),mgmtTraffic.getVlan(),mgmtTraffic.getHypervNetworkLabel());
              s_logger.info("String_Node_Str" + mgmtPhyNetwork.getId() + "String_Node_Str");
            }
          }
 catch (          InvalidParameterValueException ex) {
            throw new InvalidParameterValueException("String_Node_Str" + ex.getMessage());
          }
        }
        _capacityDao.updateCapacityState(zone.getId(),null,null,null,allocationStateStr);
        zone.setAllocationState(allocationState);
      }
      if (dhcpProvider != null) {
        zone.setDhcpProvider(dhcpProvider);
      }
      if (isPublic != null && isPublic) {
        zone.setDomainId(null);
        zone.setDomain(null);
        DedicatedResourceVO resource=_dedicatedDao.findByZoneId(zoneId);
        Long resourceId=null;
        if (resource != null) {
          resourceId=resource.getId();
          if (!_dedicatedDao.remove(resourceId)) {
            throw new CloudRuntimeException("String_Node_Str" + resourceId);
          }
          List<DedicatedResourceVO> resourcesInGroup=_dedicatedDao.listByAffinityGroupId(resource.getAffinityGroupId());
          if (resourcesInGroup.isEmpty()) {
            _affinityGroupService.deleteAffinityGroup(resource.getAffinityGroupId(),null,null,null);
          }
        }
      }
      if (!_zoneDao.update(zoneId,zone)) {
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
  }
);
  return zone;
}