Program: 106450
Project: 106450
Buggy source:
@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();
  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);
    }
    checkAccess(caller,null,true,account);
  }
  if (domainId != null) {
    Domain domain=_domainMgr.getDomain(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId + "String_Node_Str");
    }
    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);
      }
      checkAccess(caller,null,true,account);
    }
  }
  if (accountId == null) {
    if (isAdmin(caller.getType()) && listAll && domainId == null) {
      listForDomain=true;
      isRecursive=true;
      if (domainId == null) {
        domainId=caller.getDomainId();
      }
    }
 else     if (domainId != null) {
      listForDomain=true;
    }
 else {
      accountId=caller.getAccountId();
    }
  }
  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().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().getNeedsCleanup(),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) {
    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);
  }
  SearchCriteria<AccountVO> sc=sb.create();
  sc.setParameters("String_Node_Str",Account.ACCOUNT_ID_SYSTEM);
  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 (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) {
    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);
    }
  }
  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();
  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);
    }
    checkAccess(caller,null,true,account);
  }
  if (domainId != null) {
    Domain domain=_domainMgr.getDomain(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId + "String_Node_Str");
    }
    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);
      }
      checkAccess(caller,null,true,account);
    }
  }
  if (accountId == null) {
    if (isAdmin(caller.getType()) && listAll && domainId == null) {
      listForDomain=true;
      isRecursive=true;
      if (domainId == null) {
        domainId=caller.getDomainId();
      }
    }
 else     if (isAdmin(caller.getType()) && domainId != null) {
      listForDomain=true;
    }
 else {
      accountId=caller.getAccountId();
    }
  }
  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().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().getNeedsCleanup(),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) {
    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);
  }
  SearchCriteria<AccountVO> sc=sb.create();
  sc.setParameters("String_Node_Str",Account.ACCOUNT_ID_SYSTEM);
  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 (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) {
    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);
    }
  }
  return _accountDao.search(sc,searchFilter);
}