Program: 106555
Project: 106555
Buggy source:
@Override public List<InstanceGroupVO> searchForVmGroups(ListVMGroupsCmd cmd){
  Long id=cmd.getId();
  String name=cmd.getGroupName();
  String keyword=cmd.getKeyword();
  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,id,cmd.getAccountName(),cmd.getProjectId(),permittedAccounts,domainIdRecursiveListProject,cmd.listAll());
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(InstanceGroupVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<InstanceGroupVO> sb=_vmGroupDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      sb.and("String_Node_Str",sb.entity().getAccountType(),SearchCriteria.Op.EQ);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      sb.and("String_Node_Str",sb.entity().getAccountType(),SearchCriteria.Op.NEQ);
    }
  }
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.LIKE);
  SearchCriteria<InstanceGroupVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setParameters("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.setParameters("String_Node_Str",domainId);
    }
  }
  if (keyword != null) {
    SearchCriteria<InstanceGroupVO> ssc=_vmGroupDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  return _vmGroupDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<InstanceGroupVO> searchForVmGroups(ListVMGroupsCmd cmd){
  Long id=cmd.getId();
  String name=cmd.getGroupName();
  String keyword=cmd.getKeyword();
  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,id,cmd.getAccountName(),cmd.getProjectId(),permittedAccounts,domainIdRecursiveListProject,cmd.listAll(),false);
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(InstanceGroupVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<InstanceGroupVO> sb=_vmGroupDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      sb.and("String_Node_Str",sb.entity().getAccountType(),SearchCriteria.Op.EQ);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      sb.and("String_Node_Str",sb.entity().getAccountType(),SearchCriteria.Op.NEQ);
    }
  }
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.LIKE);
  SearchCriteria<InstanceGroupVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setParameters("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.setParameters("String_Node_Str",domainId);
    }
  }
  if (keyword != null) {
    SearchCriteria<InstanceGroupVO> ssc=_vmGroupDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  return _vmGroupDao.search(sc,searchFilter);
}