Program: 107448
Project: 107448
Buggy source:
@Override @DB public HostPodVO editPod(UpdatePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
  String cidr=cmd.getCidr();
  String startIp=cmd.getStartIp();
  String endIp=cmd.getEndIp();
  String gateway=cmd.getGateway();
  Long id=cmd.getId();
  String name=cmd.getName();
  Long userId=UserContext.current().getUserId();
  if (userId == null) {
    userId=Long.valueOf(User.UID_SYSTEM);
  }
  HostPodVO pod=_podDao.findById(id);
  ;
  if (pod == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + id);
  }
  long zoneId=pod.getDataCenterId();
  DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + zoneId);
  }
  if (endIp != null && startIp == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (!validPod(id)) {
    throw new InvalidParameterValueException("String_Node_Str" + id + "String_Node_Str");
  }
  if (gateway != null || cidr != null || startIp != null || endIp != null) {
    if (podHasAllocatedPrivateIPs(id)) {
      throw new InternalErrorException("String_Node_Str");
    }
  }
  String oldPodName=pod.getName();
  if (name == null) {
    name=oldPodName;
  }
  if (gateway == null) {
    gateway=pod.getGateway();
  }
  if (cidr == null) {
    cidr=pod.getCidrAddress() + "String_Node_Str" + pod.getCidrSize();
  }
  boolean checkForDuplicates=!oldPodName.equals(name);
  checkPodAttributes(id,name,pod.getDataCenterId(),gateway,cidr,startIp,endIp,checkForDuplicates);
  String cidrAddress=getCidrAddress(cidr);
  int cidrSize=getCidrSize(cidr);
  if (startIp != null && endIp == null) {
    endIp=NetUtils.getIpRangeEndIpFromCidr(cidrAddress,cidrSize);
  }
  Transaction txn=Transaction.currentTxn();
  try {
    txn.start();
    String ipRange;
    if (startIp != null) {
      _zoneDao.deletePrivateIpAddressByPod(pod.getId());
      _zoneDao.addPrivateIpAddress(zoneId,pod.getId(),startIp,endIp);
      ipRange=startIp + "String_Node_Str";
      if (endIp != null) {
        ipRange+=endIp;
      }
    }
 else {
      ipRange=pod.getDescription();
    }
    pod.setName(name);
    pod.setDataCenterId(zoneId);
    pod.setGateway(gateway);
    pod.setCidrAddress(cidrAddress);
    pod.setCidrSize(cidrSize);
    pod.setDescription(ipRange);
    if (!_podDao.update(id,pod)) {
      throw new InternalErrorException("String_Node_Str");
    }
    txn.commit();
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str" + e.getMessage(),e);
    txn.rollback();
    throw new InternalErrorException("String_Node_Str");
  }
  saveConfigurationEvent(userId,null,EventTypes.EVENT_POD_EDIT,"String_Node_Str" + name + "String_Node_Str"+ zone.getName()+ "String_Node_Str","String_Node_Str" + pod.getId(),"String_Node_Str" + zone.getId(),"String_Node_Str" + gateway,"String_Node_Str" + cidr,"String_Node_Str" + startIp,"String_Node_Str" + endIp);
  return pod;
}

Fixed version (ground truth):
@Override @DB public HostPodVO editPod(UpdatePodCmd cmd) throws InvalidParameterValueException, InternalErrorException {
  String cidr=cmd.getCidr();
  String startIp=cmd.getStartIp();
  String endIp=cmd.getEndIp();
  String gateway=cmd.getGateway();
  Long id=cmd.getId();
  String name=cmd.getPodName();
  Long userId=UserContext.current().getUserId();
  if (userId == null) {
    userId=Long.valueOf(User.UID_SYSTEM);
  }
  HostPodVO pod=_podDao.findById(id);
  ;
  if (pod == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + id);
  }
  long zoneId=pod.getDataCenterId();
  DataCenterVO zone=_zoneDao.findById(zoneId);
  if (zone == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + zoneId);
  }
  if (endIp != null && startIp == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (!validPod(id)) {
    throw new InvalidParameterValueException("String_Node_Str" + id + "String_Node_Str");
  }
  if (gateway != null || cidr != null || startIp != null || endIp != null) {
    if (podHasAllocatedPrivateIPs(id)) {
      throw new InternalErrorException("String_Node_Str");
    }
  }
  String oldPodName=pod.getName();
  if (name == null) {
    name=oldPodName;
  }
  if (gateway == null) {
    gateway=pod.getGateway();
  }
  if (cidr == null) {
    cidr=pod.getCidrAddress() + "String_Node_Str" + pod.getCidrSize();
  }
  boolean checkForDuplicates=!oldPodName.equals(name);
  checkPodAttributes(id,name,pod.getDataCenterId(),gateway,cidr,startIp,endIp,checkForDuplicates);
  String cidrAddress=getCidrAddress(cidr);
  int cidrSize=getCidrSize(cidr);
  if (startIp != null && endIp == null) {
    endIp=NetUtils.getIpRangeEndIpFromCidr(cidrAddress,cidrSize);
  }
  Transaction txn=Transaction.currentTxn();
  try {
    txn.start();
    String ipRange;
    if (startIp != null) {
      _zoneDao.deletePrivateIpAddressByPod(pod.getId());
      _zoneDao.addPrivateIpAddress(zoneId,pod.getId(),startIp,endIp);
      ipRange=startIp + "String_Node_Str";
      if (endIp != null) {
        ipRange+=endIp;
      }
    }
 else {
      ipRange=pod.getDescription();
    }
    pod.setName(name);
    pod.setDataCenterId(zoneId);
    pod.setGateway(gateway);
    pod.setCidrAddress(cidrAddress);
    pod.setCidrSize(cidrSize);
    pod.setDescription(ipRange);
    if (!_podDao.update(id,pod)) {
      throw new InternalErrorException("String_Node_Str");
    }
    txn.commit();
  }
 catch (  Exception e) {
    s_logger.error("String_Node_Str" + e.getMessage(),e);
    txn.rollback();
    throw new InternalErrorException("String_Node_Str");
  }
  saveConfigurationEvent(userId,null,EventTypes.EVENT_POD_EDIT,"String_Node_Str" + name + "String_Node_Str"+ zone.getName()+ "String_Node_Str","String_Node_Str" + pod.getId(),"String_Node_Str" + zone.getId(),"String_Node_Str" + gateway,"String_Node_Str" + cidr,"String_Node_Str" + startIp,"String_Node_Str" + endIp);
  return pod;
}