Program: 105941
Project: 105941
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_DEDICATE_RESOURCE,eventDescription="String_Node_Str") public List<DedicatedResourceVO> dedicatePod(final Long podId,final Long domainId,final String accountName){
  Long accountId=null;
  if (accountName != null) {
    Account caller=CallContext.current().getCallingAccount();
    Account owner=_accountMgr.finalizeOwner(caller,accountName,domainId,null);
    accountId=owner.getId();
  }
  List<Long> childDomainIds=getDomainChildIds(domainId);
  childDomainIds.add(domainId);
  checkAccountAndDomain(accountId,domainId);
  HostPodVO pod=_podDao.findById(podId);
  List<HostVO> hosts=null;
  if (pod == null) {
    throw new InvalidParameterValueException("String_Node_Str" + podId);
  }
 else {
    DedicatedResourceVO dedicatedPod=_dedicatedDao.findByPodId(podId);
    DedicatedResourceVO dedicatedZoneOfPod=_dedicatedDao.findByZoneId(pod.getDataCenterId());
    if (dedicatedPod != null) {
      s_logger.error("String_Node_Str" + pod.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
    }
    if (dedicatedZoneOfPod != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfPod.getDomainId()).contains(domainId);
      if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId() == domainId || domainIdInChildreanList))) {
        DataCenterVO zone=_zoneDao.findById(pod.getDataCenterId());
        s_logger.error("String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
    List<ClusterVO> clusters=_clusterDao.listByPodId(pod.getId());
    List<DedicatedResourceVO> clustersToRelease=new ArrayList<DedicatedResourceVO>();
    List<DedicatedResourceVO> hostsToRelease=new ArrayList<DedicatedResourceVO>();
    for (    ClusterVO cluster : clusters) {
      DedicatedResourceVO dCluster=_dedicatedDao.findByClusterId(cluster.getId());
      if (dCluster != null) {
        if (!(childDomainIds.contains(dCluster.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dCluster.getAccountId() == accountId) {
            clustersToRelease.add(dCluster);
          }
 else {
            s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
          }
        }
 else {
          if (dCluster.getAccountId() == null && dCluster.getDomainId() == domainId) {
            clustersToRelease.add(dCluster);
          }
        }
      }
    }
    for (    DedicatedResourceVO dr : clustersToRelease) {
      releaseDedicatedResource(null,null,dr.getClusterId(),null);
    }
    hosts=_hostDao.findByPodId(pod.getId());
    for (    HostVO host : hosts) {
      DedicatedResourceVO dHost=_dedicatedDao.findByHostId(host.getId());
      if (dHost != null) {
        if (!(getDomainChildIds(domainId).contains(dHost.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dHost.getAccountId() == accountId) {
            hostsToRelease.add(dHost);
          }
 else {
            s_logger.error("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
          }
        }
 else {
          if (dHost.getAccountId() == null && dHost.getDomainId() == domainId) {
            hostsToRelease.add(dHost);
          }
        }
      }
    }
    for (    DedicatedResourceVO dr : hostsToRelease) {
      releaseDedicatedResource(null,null,null,dr.getHostId());
    }
  }
  checkHostsSuitabilityForExplicitDedication(accountId,childDomainIds,hosts);
  final Long accountIdFinal=accountId;
  return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>(){
    @Override public List<DedicatedResourceVO> doInTransaction(    TransactionStatus status){
      AffinityGroup group=findOrCreateDedicatedAffinityGroup(domainId,accountIdFinal);
      if (group == null) {
        s_logger.error("String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str");
      }
      DedicatedResourceVO dedicatedResource=new DedicatedResourceVO(null,podId,null,null,null,null,group.getId());
      try {
        dedicatedResource.setDomainId(domainId);
        if (accountIdFinal != null) {
          dedicatedResource.setAccountId(accountIdFinal);
        }
        dedicatedResource=_dedicatedDao.persist(dedicatedResource);
      }
 catch (      Exception e) {
        s_logger.error("String_Node_Str" + e.getMessage(),e);
        throw new CloudRuntimeException("String_Node_Str");
      }
      List<DedicatedResourceVO> result=new ArrayList<DedicatedResourceVO>();
      result.add(dedicatedResource);
      return result;
    }
  }
);
}

Fixed version (ground truth):
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_DEDICATE_RESOURCE,eventDescription="String_Node_Str") public List<DedicatedResourceVO> dedicatePod(final Long podId,final Long domainId,final String accountName){
  Long accountId=null;
  if (accountName != null) {
    Account caller=CallContext.current().getCallingAccount();
    Account owner=_accountMgr.finalizeOwner(caller,accountName,domainId,null);
    accountId=owner.getId();
  }
  List<Long> childDomainIds=getDomainChildIds(domainId);
  childDomainIds.add(domainId);
  checkAccountAndDomain(accountId,domainId);
  HostPodVO pod=_podDao.findById(podId);
  List<HostVO> hosts=null;
  if (pod == null) {
    throw new InvalidParameterValueException("String_Node_Str" + podId);
  }
 else {
    DedicatedResourceVO dedicatedPod=_dedicatedDao.findByPodId(podId);
    DedicatedResourceVO dedicatedZoneOfPod=_dedicatedDao.findByZoneId(pod.getDataCenterId());
    if (dedicatedPod != null) {
      s_logger.error("String_Node_Str" + pod.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
    }
    if (dedicatedZoneOfPod != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfPod.getDomainId()).contains(domainId);
      if (dedicatedZoneOfPod.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfPod.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        DataCenterVO zone=_zoneDao.findById(pod.getDataCenterId());
        s_logger.error("String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
    List<ClusterVO> clusters=_clusterDao.listByPodId(pod.getId());
    List<DedicatedResourceVO> clustersToRelease=new ArrayList<DedicatedResourceVO>();
    List<DedicatedResourceVO> hostsToRelease=new ArrayList<DedicatedResourceVO>();
    for (    ClusterVO cluster : clusters) {
      DedicatedResourceVO dCluster=_dedicatedDao.findByClusterId(cluster.getId());
      if (dCluster != null) {
        if (!(childDomainIds.contains(dCluster.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dCluster.getAccountId().equals(accountId)) {
            clustersToRelease.add(dCluster);
          }
 else {
            s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
          }
        }
 else {
          if (dCluster.getAccountId() == null && dCluster.getDomainId().equals(domainId)) {
            clustersToRelease.add(dCluster);
          }
        }
      }
    }
    for (    DedicatedResourceVO dr : clustersToRelease) {
      releaseDedicatedResource(null,null,dr.getClusterId(),null);
    }
    hosts=_hostDao.findByPodId(pod.getId());
    for (    HostVO host : hosts) {
      DedicatedResourceVO dHost=_dedicatedDao.findByHostId(host.getId());
      if (dHost != null) {
        if (!(getDomainChildIds(domainId).contains(dHost.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dHost.getAccountId().equals(accountId)) {
            hostsToRelease.add(dHost);
          }
 else {
            s_logger.error("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
            throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ pod.getName()+ "String_Node_Str");
          }
        }
 else {
          if (dHost.getAccountId() == null && dHost.getDomainId().equals(domainId)) {
            hostsToRelease.add(dHost);
          }
        }
      }
    }
    for (    DedicatedResourceVO dr : hostsToRelease) {
      releaseDedicatedResource(null,null,null,dr.getHostId());
    }
  }
  checkHostsSuitabilityForExplicitDedication(accountId,childDomainIds,hosts);
  final Long accountIdFinal=accountId;
  return Transaction.execute(new TransactionCallback<List<DedicatedResourceVO>>(){
    @Override public List<DedicatedResourceVO> doInTransaction(    TransactionStatus status){
      AffinityGroup group=findOrCreateDedicatedAffinityGroup(domainId,accountIdFinal);
      if (group == null) {
        s_logger.error("String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str");
      }
      DedicatedResourceVO dedicatedResource=new DedicatedResourceVO(null,podId,null,null,null,null,group.getId());
      try {
        dedicatedResource.setDomainId(domainId);
        if (accountIdFinal != null) {
          dedicatedResource.setAccountId(accountIdFinal);
        }
        dedicatedResource=_dedicatedDao.persist(dedicatedResource);
      }
 catch (      Exception e) {
        s_logger.error("String_Node_Str" + e.getMessage(),e);
        throw new CloudRuntimeException("String_Node_Str");
      }
      List<DedicatedResourceVO> result=new ArrayList<DedicatedResourceVO>();
      result.add(dedicatedResource);
      return result;
    }
  }
);
}