Program: 107047
Project: 107047
Buggy source:
@Override public List<AccountVO> searchForAccounts(ListAccountsCmd cmd){
  Account account=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  Long accountId=cmd.getId();
  String accountName=null;
  Boolean isRecursive=cmd.isRecursive();
  if (isRecursive == null) {
    isRecursive=false;
  }
  if (accountId != null && accountId == 1) {
    List<AccountVO> emptyList=new ArrayList<AccountVO>();
    return emptyList;
  }
  if ((account == null) || isAdmin(account.getType())) {
    accountName=cmd.getSearchName();
    if (domainId == null) {
      domainId=((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
      isRecursive=true;
    }
 else     if (account != null) {
      if (!_domainDao.isChildDomain(account.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
    }
  }
 else {
    accountId=account.getId();
    accountName=account.getAccountName();
  }
  Filter searchFilter=new Filter(AccountVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  Object type=cmd.getAccountType();
  Object state=cmd.getState();
  Object isCleanupRequired=cmd.isCleanupRequired();
  Object keyword=cmd.getKeyword();
  SearchBuilder<AccountVO> sb=_accountDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountName(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getNeedsCleanup(),SearchCriteria.Op.EQ);
  if ((accountId == null) && (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);
  }
 else   if ((accountId == null) && (domainId != null) && !isRecursive) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.EQ);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  SearchCriteria<AccountVO> sc=sb.create();
  if (keyword != null) {
    SearchCriteria<AccountVO> ssc=_accountDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,ssc);
  }
  if (accountName != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + accountName + "String_Node_Str");
  }
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
  }
 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",domain.getPath());
    }
    sc.setParameters("String_Node_Str",1L);
  }
 else {
    sc.setParameters("String_Node_Str",1L);
  }
  if (type != null) {
    sc.setParameters("String_Node_Str",type);
  }
  if (state != null) {
    sc.setParameters("String_Node_Str",state);
  }
  if (isCleanupRequired != null) {
    sc.setParameters("String_Node_Str",isCleanupRequired);
  }
  return _accountDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<AccountVO> searchForAccounts(ListAccountsCmd cmd){
  Account caller=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  Long accountId=cmd.getId();
  String accountName=cmd.getSearchName();
  Boolean isRecursive=cmd.isRecursive();
  if (isRecursive == null) {
    isRecursive=false;
  }
  if (accountId != null && accountId.longValue() == 1L) {
    List<AccountVO> emptyList=new ArrayList<AccountVO>();
    return emptyList;
  }
  if (isAdmin(caller.getType())) {
    if (domainId == null) {
      domainId=caller.getDomainId();
      isRecursive=true;
    }
 else {
      Domain domain=_domainDao.findById(domainId);
      if (domain == null) {
        throw new InvalidParameterValueException("String_Node_Str" + domainId + "String_Node_Str");
      }
      _accountMgr.checkAccess(caller,domain);
      if (accountName != null) {
        Account account=_accountDao.findActiveAccount(accountName,domainId);
        if (account == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        _accountMgr.checkAccess(caller,account);
      }
    }
  }
 else {
    accountId=caller.getId();
  }
  Filter searchFilter=new Filter(AccountVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  Object type=cmd.getAccountType();
  Object state=cmd.getState();
  Object isCleanupRequired=cmd.isCleanupRequired();
  Object keyword=cmd.getKeyword();
  SearchBuilder<AccountVO> sb=_accountDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountName(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getNeedsCleanup(),SearchCriteria.Op.EQ);
  if ((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);
  }
 else   if ((domainId != null) && !isRecursive) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.EQ);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  SearchCriteria<AccountVO> sc=sb.create();
  if (keyword != null) {
    SearchCriteria<AccountVO> ssc=_accountDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,ssc);
  }
  if (accountName != null) {
    sc.setParameters("String_Node_Str",accountName);
  }
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
  }
  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",domain.getPath());
    }
    sc.setParameters("String_Node_Str",1L);
  }
 else {
    sc.setParameters("String_Node_Str",1L);
  }
  if (type != null) {
    sc.setParameters("String_Node_Str",type);
  }
  if (state != null) {
    sc.setParameters("String_Node_Str",state);
  }
  if (isCleanupRequired != null) {
    sc.setParameters("String_Node_Str",isCleanupRequired);
  }
  return _accountDao.search(sc,searchFilter);
}