Program: 105938
Project: 105938
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_DEDICATE_RESOURCE,eventDescription="String_Node_Str") public List<DedicatedResourceVO> dedicateHost(final Long hostId,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();
  }
  checkAccountAndDomain(accountId,domainId);
  HostVO host=_hostDao.findById(hostId);
  if (host == null) {
    throw new InvalidParameterValueException("String_Node_Str" + hostId);
  }
 else {
    if (host.getType() != Host.Type.Routing) {
      throw new CloudRuntimeException("String_Node_Str" + host.getName());
    }
    DedicatedResourceVO dedicatedHost=_dedicatedDao.findByHostId(hostId);
    DedicatedResourceVO dedicatedClusterOfHost=_dedicatedDao.findByClusterId(host.getClusterId());
    DedicatedResourceVO dedicatedPodOfHost=_dedicatedDao.findByPodId(host.getPodId());
    DedicatedResourceVO dedicatedZoneOfHost=_dedicatedDao.findByZoneId(host.getDataCenterId());
    if (dedicatedHost != null) {
      s_logger.error("String_Node_Str" + host.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str");
    }
    if (dedicatedClusterOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
      if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
        ClusterVO cluster=_clusterDao.findById(host.getClusterId());
        s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str");
      }
    }
    if (dedicatedPodOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
      if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
        HostPodVO pod=_podDao.findById(host.getPodId());
        s_logger.error("String_Node_Str" + pod.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
      }
    }
    if (dedicatedZoneOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
      if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId() == domainId || domainIdInChildreanList))) {
        DataCenterVO zone=_zoneDao.findById(host.getDataCenterId());
        s_logger.error("String_Node_Str" + zone.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
  }
  List<Long> childDomainIds=getDomainChildIds(domainId);
  childDomainIds.add(domainId);
  checkHostSuitabilityForExplicitDedication(accountId,childDomainIds,hostId);
  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,null,hostId,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> dedicateHost(final Long hostId,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();
  }
  checkAccountAndDomain(accountId,domainId);
  HostVO host=_hostDao.findById(hostId);
  if (host == null) {
    throw new InvalidParameterValueException("String_Node_Str" + hostId);
  }
 else {
    if (host.getType() != Host.Type.Routing) {
      throw new CloudRuntimeException("String_Node_Str" + host.getName());
    }
    DedicatedResourceVO dedicatedHost=_dedicatedDao.findByHostId(hostId);
    DedicatedResourceVO dedicatedClusterOfHost=_dedicatedDao.findByClusterId(host.getClusterId());
    DedicatedResourceVO dedicatedPodOfHost=_dedicatedDao.findByPodId(host.getPodId());
    DedicatedResourceVO dedicatedZoneOfHost=_dedicatedDao.findByZoneId(host.getDataCenterId());
    if (dedicatedHost != null) {
      s_logger.error("String_Node_Str" + host.getName() + "String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str" + host.getName() + "String_Node_Str");
    }
    if (dedicatedClusterOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedClusterOfHost.getDomainId()).contains(domainId);
      if (dedicatedClusterOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedClusterOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        ClusterVO cluster=_clusterDao.findById(host.getClusterId());
        s_logger.error("String_Node_Str" + cluster.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + cluster.getName() + "String_Node_Str");
      }
    }
    if (dedicatedPodOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedPodOfHost.getDomainId()).contains(domainId);
      if (dedicatedPodOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedPodOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        HostPodVO pod=_podDao.findById(host.getPodId());
        s_logger.error("String_Node_Str" + pod.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + pod.getName() + "String_Node_Str");
      }
    }
    if (dedicatedZoneOfHost != null) {
      boolean domainIdInChildreanList=getDomainChildIds(dedicatedZoneOfHost.getDomainId()).contains(domainId);
      if (dedicatedZoneOfHost.getAccountId() != null || (accountId == null && !domainIdInChildreanList) || (accountId != null && !(dedicatedZoneOfHost.getDomainId().equals(domainId) || domainIdInChildreanList))) {
        DataCenterVO zone=_zoneDao.findById(host.getDataCenterId());
        s_logger.error("String_Node_Str" + zone.getName() + "String_Node_Str");
        throw new CloudRuntimeException("String_Node_Str" + zone.getName() + "String_Node_Str");
      }
    }
  }
  List<Long> childDomainIds=getDomainChildIds(domainId);
  childDomainIds.add(domainId);
  checkHostSuitabilityForExplicitDedication(accountId,childDomainIds,hostId);
  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,null,hostId,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;
    }
  }
);
}