Program: 89177
Project: 89177
Buggy source:
@Override public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd){
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,null,cmd.getAccountName(),null,permittedAccounts,domainIdRecursiveListProject,cmd.listAll());
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(AsyncJobVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<AsyncJobVO> sb=_jobDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  SearchBuilder<AccountVO> accountSearch=null;
  boolean accountJoinIsDone=false;
  if (permittedAccounts.isEmpty() && domainId != null) {
    accountSearch=_accountDao.createSearchBuilder();
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getId(),SearchCriteria.Op.EQ);
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    accountJoinIsDone=true;
    accountSearch.join("String_Node_Str",domainSearch,accountSearch.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    if (accountSearch == null) {
      accountSearch=_accountDao.createSearchBuilder();
    }
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.EQ);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.NEQ);
    }
    if (!accountJoinIsDone) {
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
  }
  Object keyword=cmd.getKeyword();
  Object startDate=cmd.getStartDate();
  SearchCriteria<AsyncJobVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  }
  if (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    if (isRecursive) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domainId);
    }
  }
  if (keyword != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
  }
  if (startDate != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.GTEQ,startDate);
  }
  return _jobDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<AsyncJobVO> searchForAsyncJobs(ListAsyncJobsCmd cmd){
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,null,cmd.getAccountName(),null,permittedAccounts,domainIdRecursiveListProject,cmd.listAll(),false);
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(AsyncJobVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<AsyncJobVO> sb=_jobDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  SearchBuilder<AccountVO> accountSearch=null;
  boolean accountJoinIsDone=false;
  if (permittedAccounts.isEmpty() && domainId != null) {
    accountSearch=_accountDao.createSearchBuilder();
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getId(),SearchCriteria.Op.EQ);
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    accountJoinIsDone=true;
    accountSearch.join("String_Node_Str",domainSearch,accountSearch.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    if (accountSearch == null) {
      accountSearch=_accountDao.createSearchBuilder();
    }
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.EQ);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.NEQ);
    }
    if (!accountJoinIsDone) {
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
  }
  Object keyword=cmd.getKeyword();
  Object startDate=cmd.getStartDate();
  SearchCriteria<AsyncJobVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  }
  if (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    if (isRecursive) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domainId);
    }
  }
  if (keyword != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
  }
  if (startDate != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.GTEQ,startDate);
  }
  return _jobDao.search(sc,searchFilter);
}