Program: 105940
Project: 105940
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_DEDICATE_RESOURCE,eventDescription="String_Node_Str") public List<DedicatedResourceVO> dedicateCluster(final Long clusterId,final Long domainId,final String accountName){
  Long accountId=null;
  List<HostVO> hosts=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);
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (cluster == null) {
    throw new InvalidParameterValueException("String_Node_Str" + clusterId);
  }
 else {
    DedicatedResourceVO dedicatedCluster=_dedicatedDao.findByClusterId(clusterId);
    DedicatedResourceVO dedicatedPodOfCluster=_dedicatedDao.findByPodId(cluster.getPodId());
    DedicatedResourceVO dedicatedZoneOfCluster=_dedicatedDao.findByZoneId(cluster.getDataCenterId());
    if (dedicatedCluster != null) {
      s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str");
    }
    if (dedicatedPodOfCluster != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedPodOfCluster.getDomainId()).contains(domainId);
      if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId() == domainId || domainIdInChildreanList))) {
        s_logger.error("String_Node_Str");
        HostPodVO pod=_podDao.findById(cluster.getPodId());
        throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
      }
    }
    if (dedicatedZoneOfCluster != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfCluster.getDomainId()).contains(domainId);
      if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId() == domainId || domainIdInChildreanList))) {
        s_logger.error("String_Node_Str");
        DataCenterVO zone=_zoneDao.findById(cluster.getDataCenterId());
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
    hosts=_hostDao.findByClusterId(cluster.getId());
    List<DedicatedResourceVO> hostsToRelease=new ArrayList<DedicatedResourceVO>();
    for (    HostVO host : hosts) {
      DedicatedResourceVO dHost=_dedicatedDao.findByHostId(host.getId());
      if (dHost != null) {
        if (!(childDomainIds.contains(dHost.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ cluster.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dHost.getAccountId() == accountId) {
            hostsToRelease.add(dHost);
          }
 else {
            s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str"+ accountName);
            throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ accountName);
          }
        }
 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,null,clusterId,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> dedicateCluster(final Long clusterId,final Long domainId,final String accountName){
  Long accountId=null;
  List<HostVO> hosts=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);
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (cluster == null) {
    throw new InvalidParameterValueException("String_Node_Str" + clusterId);
  }
 else {
    DedicatedResourceVO dedicatedCluster=_dedicatedDao.findByClusterId(clusterId);
    DedicatedResourceVO dedicatedPodOfCluster=_dedicatedDao.findByPodId(cluster.getPodId());
    DedicatedResourceVO dedicatedZoneOfCluster=_dedicatedDao.findByZoneId(cluster.getDataCenterId());
    if (dedicatedCluster != null) {
      s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str");
    }
    if (dedicatedPodOfCluster != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedPodOfCluster.getDomainId()).contains(domainId);
      if (dedicatedPodOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        s_logger.error("String_Node_Str");
        HostPodVO pod=_podDao.findById(cluster.getPodId());
        throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
      }
    }
    if (dedicatedZoneOfCluster != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfCluster.getDomainId()).contains(domainId);
      if (dedicatedZoneOfCluster.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfCluster.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        s_logger.error("String_Node_Str");
        DataCenterVO zone=_zoneDao.findById(cluster.getDataCenterId());
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
    hosts=_hostDao.findByClusterId(cluster.getId());
    List<DedicatedResourceVO> hostsToRelease=new ArrayList<DedicatedResourceVO>();
    for (    HostVO host : hosts) {
      DedicatedResourceVO dHost=_dedicatedDao.findByHostId(host.getId());
      if (dHost != null) {
        if (!(childDomainIds.contains(dHost.getDomainId()))) {
          throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str"+ cluster.getName()+ "String_Node_Str");
        }
        if (accountId != null) {
          if (dHost.getAccountId().equals(accountId)) {
            hostsToRelease.add(dHost);
          }
 else {
            s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str"+ accountName);
            throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str"+ accountName);
          }
        }
 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,null,clusterId,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;
    }
  }
);
}