Program: 106823
Project: 106823
Buggy source:
@Override public DataCenter editZone(UpdateZoneCmd cmd){
  Long zoneId=cmd.getId();
  String zoneName=cmd.getZoneName();
  String dns1=cmd.getDns1();
  String dns2=cmd.getDns2();
  String internalDns1=cmd.getInternalDns1();
  String internalDns2=cmd.getInternalDns2();
  String vnetRange=cmd.getVlan();
  String guestCidr=cmd.getGuestCidrAddress();
  Long userId=UserContext.current().getCallerUserId();
  int startVnetRange=0;
  int stopVnetRange=0;
  Boolean isPublic=cmd.isPublic();
  String allocationStateStr=cmd.getAllocationState();
  String dhcpProvider=cmd.getDhcpProvider();
  Map detailsMap=cmd.getDetails();
  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 (userId == null) {
    userId=Long.valueOf(User.UID_SYSTEM);
  }
  DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  if (zoneName == null) {
    zoneName=zone.getName();
  }
  if (zone.getNetworkType() == NetworkType.Basic) {
    if (vnetRange != null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getNetworkType() + "String_Node_Str");
    }
 else     if (guestCidr != null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getNetworkType() + "String_Node_Str");
    }
  }
  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");
  }
  if (vnetRange != null) {
    if (zoneHasAllocatedVnets(zoneId)) {
      throw new CloudRuntimeException("String_Node_Str");
    }
    String[] startStopRange=new String[2];
    startStopRange=vnetRange.split("String_Node_Str");
    if (startStopRange.length == 1) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startStopRange[0] == null || startStopRange[1] == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    try {
      startVnetRange=Integer.parseInt(startStopRange[0]);
      stopVnetRange=Integer.parseInt(startStopRange[1]);
    }
 catch (    NumberFormatException e) {
      s_logger.warn("String_Node_Str",e);
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startVnetRange < 0 || stopVnetRange > 4096) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startVnetRange > stopVnetRange) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  String oldZoneName=zone.getName();
  if (zoneName == null) {
    zoneName=oldZoneName;
  }
  boolean dnsUpdate=false;
  if (dns1 != null || dns2 != null) {
    dnsUpdate=true;
  }
  if (dns1 == null) {
    dns1=zone.getDns1();
  }
  if (dns2 == null) {
    dns2=zone.getDns2();
  }
  if (internalDns1 == null) {
    internalDns1=zone.getInternalDns1();
  }
  if (guestCidr == null) {
    guestCidr=zone.getGuestNetworkCidr();
  }
  boolean checkForDuplicates=!zoneName.equals(oldZoneName);
  checkZoneParameters(zoneName,dns1,dns2,internalDns1,internalDns2,checkForDuplicates,null,allocationStateStr);
  zone.setName(zoneName);
  zone.setDns1(dns1);
  zone.setDns2(dns2);
  zone.setInternalDns1(internalDns1);
  zone.setInternalDns2(internalDns2);
  zone.setGuestNetworkCidr(guestCidr);
  if (vnetRange != null) {
    zone.setVnet(vnetRange);
  }
  if (isPublic != null && isPublic) {
    zone.setDomainId(null);
    zone.setDomain(null);
  }
  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);
    zone.setAllocationState(allocationState);
  }
  if (dhcpProvider != null) {
    zone.setDhcpProvider(dhcpProvider);
  }
  if (!_zoneDao.update(zoneId,zone)) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  if (vnetRange != null) {
    String[] tokens=vnetRange.split("String_Node_Str");
    int begin=Integer.parseInt(tokens[0]);
    int end=tokens.length == 1 ? (begin) : Integer.parseInt(tokens[1]);
    _zoneDao.deleteVnet(zoneId);
    _zoneDao.addVnet(zone.getId(),begin,end);
  }
  return zone;
}

Fixed version (ground truth):
@Override public DataCenter editZone(UpdateZoneCmd cmd){
  Long zoneId=cmd.getId();
  String zoneName=cmd.getZoneName();
  String dns1=cmd.getDns1();
  String dns2=cmd.getDns2();
  String internalDns1=cmd.getInternalDns1();
  String internalDns2=cmd.getInternalDns2();
  String vnetRange=cmd.getVlan();
  String guestCidr=cmd.getGuestCidrAddress();
  Long userId=UserContext.current().getCallerUserId();
  int startVnetRange=0;
  int stopVnetRange=0;
  Boolean isPublic=cmd.isPublic();
  String allocationStateStr=cmd.getAllocationState();
  String dhcpProvider=cmd.getDhcpProvider();
  Map detailsMap=cmd.getDetails();
  String networkDomain=cmd.getDomain();
  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 (userId == null) {
    userId=Long.valueOf(User.UID_SYSTEM);
  }
  DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  if (zoneName == null) {
    zoneName=zone.getName();
  }
  if (zone.getNetworkType() == NetworkType.Basic) {
    if (vnetRange != null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getNetworkType() + "String_Node_Str");
    }
 else     if (guestCidr != null) {
      throw new InvalidParameterValueException("String_Node_Str" + zone.getNetworkType() + "String_Node_Str");
    }
  }
  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");
  }
  if (vnetRange != null) {
    if (zoneHasAllocatedVnets(zoneId)) {
      throw new CloudRuntimeException("String_Node_Str");
    }
    String[] startStopRange=new String[2];
    startStopRange=vnetRange.split("String_Node_Str");
    if (startStopRange.length == 1) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startStopRange[0] == null || startStopRange[1] == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    try {
      startVnetRange=Integer.parseInt(startStopRange[0]);
      stopVnetRange=Integer.parseInt(startStopRange[1]);
    }
 catch (    NumberFormatException e) {
      s_logger.warn("String_Node_Str",e);
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startVnetRange < 0 || stopVnetRange > 4096) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (startVnetRange > stopVnetRange) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  String oldZoneName=zone.getName();
  if (zoneName == null) {
    zoneName=oldZoneName;
  }
  boolean dnsUpdate=false;
  if (dns1 != null || dns2 != null) {
    dnsUpdate=true;
  }
  if (dns1 == null) {
    dns1=zone.getDns1();
  }
  if (dns2 == null) {
    dns2=zone.getDns2();
  }
  if (internalDns1 == null) {
    internalDns1=zone.getInternalDns1();
  }
  if (guestCidr == null) {
    guestCidr=zone.getGuestNetworkCidr();
  }
  if (networkDomain != null) {
    if (!NetUtils.verifyDomainName(networkDomain)) {
      throw new InvalidParameterValueException("String_Node_Str" + "String_Node_Str");
    }
  }
 else {
    networkDomain=zone.getDomain();
  }
  boolean checkForDuplicates=!zoneName.equals(oldZoneName);
  checkZoneParameters(zoneName,dns1,dns2,internalDns1,internalDns2,checkForDuplicates,null,allocationStateStr);
  zone.setName(zoneName);
  zone.setDns1(dns1);
  zone.setDns2(dns2);
  zone.setInternalDns1(internalDns1);
  zone.setInternalDns2(internalDns2);
  zone.setGuestNetworkCidr(guestCidr);
  zone.setDomain(networkDomain);
  if (vnetRange != null) {
    zone.setVnet(vnetRange);
  }
  if (isPublic != null && isPublic) {
    zone.setDomainId(null);
    zone.setDomain(null);
  }
  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);
    zone.setAllocationState(allocationState);
  }
  if (dhcpProvider != null) {
    zone.setDhcpProvider(dhcpProvider);
  }
  if (!_zoneDao.update(zoneId,zone)) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  if (vnetRange != null) {
    String[] tokens=vnetRange.split("String_Node_Str");
    int begin=Integer.parseInt(tokens[0]);
    int end=tokens.length == 1 ? (begin) : Integer.parseInt(tokens[1]);
    _zoneDao.deleteVnet(zoneId);
    _zoneDao.addVnet(zone.getId(),begin,end);
  }
  return zone;
}