Program: 105085
Project: 105085
Buggy source:
private Pair<List<AccountJoinVO>,Integer> searchForAccountsInternal(ListAccountsCmd cmd){
  Account caller=CallContext.current().getCallingAccount();
  Long domainId=cmd.getDomainId();
  Long accountId=cmd.getId();
  String accountName=cmd.getSearchName();
  boolean isRecursive=cmd.isRecursive();
  boolean listAll=cmd.listAll();
  Boolean listForDomain=false;
  if (accountId != null) {
    Account account=_accountDao.findById(accountId);
    if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
      throw new InvalidParameterValueException("String_Node_Str" + accountId);
    }
    _accountMgr.checkAccess(caller,null,true,account);
  }
  if (domainId != null) {
    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 || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
        throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
      }
      _accountMgr.checkAccess(caller,null,true,account);
    }
  }
  if (accountId == null) {
    if (_accountMgr.isAdmin(caller.getId()) && listAll && domainId == null) {
      listForDomain=true;
      isRecursive=true;
      if (domainId == null) {
        domainId=caller.getDomainId();
      }
    }
 else     if (_accountMgr.isAdmin(caller.getId()) && domainId != null) {
      listForDomain=true;
    }
 else {
      accountId=caller.getAccountId();
    }
  }
  Filter searchFilter=new Filter(AccountJoinVO.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<AccountJoinVO> sb=_accountJoinDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountName(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  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().isNeedsCleanup(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.NEQ);
  if (listForDomain && isRecursive) {
    sb.and("String_Node_Str",sb.entity().getDomainPath(),SearchCriteria.Op.LIKE);
  }
  SearchCriteria<AccountJoinVO> sc=sb.create();
  sc.setParameters("String_Node_Str",Account.ACCOUNT_ID_SYSTEM);
  if (keyword != null) {
    SearchCriteria<AccountJoinVO> ssc=_accountJoinDao.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 (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);
  }
  if (accountName != null) {
    sc.setParameters("String_Node_Str",accountName);
  }
  sc.setParameters("String_Node_Str",5);
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
  }
  if (listForDomain) {
    if (isRecursive) {
      Domain domain=_domainDao.findById(domainId);
      sc.setParameters("String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setParameters("String_Node_Str",domainId);
    }
  }
  return _accountJoinDao.searchAndCount(sc,searchFilter);
}

Fixed version (ground truth):
private Pair<List<AccountJoinVO>,Integer> searchForAccountsInternal(ListAccountsCmd cmd){
  Account caller=CallContext.current().getCallingAccount();
  Long domainId=cmd.getDomainId();
  Long accountId=cmd.getId();
  String accountName=cmd.getSearchName();
  boolean isRecursive=cmd.isRecursive();
  boolean listAll=cmd.listAll();
  boolean callerIsAdmin=_accountMgr.isAdmin(caller.getId());
  Account account;
  Domain domain=null;
  if (domainId != null) {
    domain=_domainDao.findById(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId + "String_Node_Str");
    }
    _accountMgr.checkAccess(caller,domain);
  }
  if (accountId == null) {
    if (listAll && callerIsAdmin) {
      if (domainId == null) {
        domainId=caller.getDomainId();
      }
      isRecursive=true;
    }
 else     if (!callerIsAdmin || domainId == null) {
      accountId=caller.getAccountId();
    }
  }
 else   if (domainId != null && accountName != null) {
    account=_accountDao.findActiveAccount(accountName,domainId);
    if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
      throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
    }
    _accountMgr.checkAccess(caller,null,true,account);
  }
 else {
    if (domainId == null) {
      account=_accountDao.findById(accountId);
    }
 else {
      account=_accountDao.findActiveAccountById(accountId,domainId);
    }
    if (account == null || account.getId() == Account.ACCOUNT_ID_SYSTEM) {
      throw new InvalidParameterValueException("String_Node_Str" + accountId + (domainId == null ? "String_Node_Str" : "String_Node_Str" + domainId));
    }
    _accountMgr.checkAccess(caller,null,true,account);
  }
  Filter searchFilter=new Filter(AccountJoinVO.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<AccountJoinVO> sb=_accountJoinDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountName(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  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().isNeedsCleanup(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.NEQ);
  if (domainId != null && isRecursive) {
    sb.and("String_Node_Str",sb.entity().getDomainPath(),SearchCriteria.Op.LIKE);
  }
  SearchCriteria<AccountJoinVO> sc=sb.create();
  sc.setParameters("String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  sc.setParameters("String_Node_Str",Account.ACCOUNT_ID_SYSTEM);
  if (keyword != null) {
    SearchCriteria<AccountJoinVO> ssc=_accountJoinDao.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 (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);
  }
  if (accountName != null) {
    sc.setParameters("String_Node_Str",accountName);
  }
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
  }
  if (domainId != null) {
    if (isRecursive) {
      if (domain == null) {
        domain=_domainDao.findById(domainId);
      }
      sc.setParameters("String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setParameters("String_Node_Str",domainId);
    }
  }
  return _accountJoinDao.searchAndCount(sc,searchFilter);
}