Program: 107335
Project: 107335
Buggy source:
@Override public DomainVO updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
  Long domainId=cmd.getId();
  String domainName=cmd.getDomainName();
  DomainVO domain=_domainDao.findById(domainId);
  if (domain == null) {
    throw new InvalidParameterValueException("String_Node_Str" + domainId);
  }
 else   if (domain.getParent() == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Account account=UserContext.current().getAccount();
  if ((account != null) && !isChildDomain(account.getDomainId(),domain.getId())) {
    throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
  }
  if (domainName == null || domainName.equals(domain.getName())) {
    return _domainDao.findById(domainId);
  }
  SearchCriteria<DomainVO> sc=_domainDao.createSearchCriteria();
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,domainName);
  List<DomainVO> domains=_domainDao.search(sc,null);
  if ((domains == null) || domains.isEmpty()) {
    _domainDao.update(domainId,domainName);
    domain=_domainDao.findById(domainId);
    EventUtils.saveEvent(new Long(1),domain.getAccountId(),EventVO.LEVEL_INFO,EventTypes.EVENT_DOMAIN_UPDATE,"String_Node_Str" + domainName + "String_Node_Str");
    return _domainDao.findById(domainId);
  }
 else {
    domain=_domainDao.findById(domainId);
    EventUtils.saveEvent(new Long(1),domain.getAccountId(),EventVO.LEVEL_ERROR,EventTypes.EVENT_DOMAIN_UPDATE,"String_Node_Str" + domain.getName() + "String_Node_Str"+ domainName+ "String_Node_Str");
    s_logger.error("String_Node_Str" + domainName + "String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str" + domainId);
  }
}

Fixed version (ground truth):
@Override public DomainVO updateDomain(UpdateDomainCmd cmd) throws InvalidParameterValueException, PermissionDeniedException {
  Long domainId=cmd.getId();
  String domainName=cmd.getDomainName();
  DomainVO domain=_domainDao.findById(domainId);
  if (domain == null) {
    throw new InvalidParameterValueException("String_Node_Str" + domainId);
  }
 else   if (domain.getParent() == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Account account=UserContext.current().getAccount();
  if ((account != null) && !isChildDomain(account.getDomainId(),domain.getId())) {
    throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
  }
  if (domainName == null || domainName.equals(domain.getName())) {
    return _domainDao.findById(domainId);
  }
  SearchCriteria<DomainVO> sc=_domainDao.createSearchCriteria();
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,domainName);
  List<DomainVO> domains=_domainDao.search(sc,null);
  if ((domains == null) || domains.isEmpty()) {
    domain=_domainDao.findById(domainId);
    String updatedDomainPath=getUpdatedDomainPath(domain.getPath(),domainName);
    updateDomainChildren(domain,updatedDomainPath);
    _domainDao.update(domainId,domainName,updatedDomainPath);
    EventUtils.saveEvent(new Long(1),domain.getAccountId(),EventVO.LEVEL_INFO,EventTypes.EVENT_DOMAIN_UPDATE,"String_Node_Str" + domainName + "String_Node_Str");
    return _domainDao.findById(domainId);
  }
 else {
    domain=_domainDao.findById(domainId);
    EventUtils.saveEvent(new Long(1),domain.getAccountId(),EventVO.LEVEL_ERROR,EventTypes.EVENT_DOMAIN_UPDATE,"String_Node_Str" + domain.getName() + "String_Node_Str"+ domainName+ "String_Node_Str");
    s_logger.error("String_Node_Str" + domainName + "String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str" + domainId);
  }
}