Program: 89245
Project: 89245
Buggy source:
@Override public List<SnapshotVO> listSnapshots(ListSnapshotsCmd cmd){
  Long volumeId=cmd.getVolumeId();
  Boolean isRecursive=cmd.isRecursive();
  Long projectId=cmd.getProjectId();
  if (volumeId != null) {
    VolumeVO volume=_volsDao.findById(volumeId);
    if (volume != null) {
      _accountMgr.checkAccess(UserContext.current().getCaller(),null,volume);
    }
  }
  Account caller=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  List<Long> permittedAccounts=new ArrayList<Long>();
  if ((caller == null) || _accountMgr.isAdmin(caller.getType())) {
    if (domainId != null) {
      if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
    }
 else     if ((caller != null) && ((caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN))) {
      domainId=caller.getDomainId();
      isRecursive=true;
    }
    if (domainId != null && accountName != null) {
      Account userAccount=_accountDao.findActiveAccount(accountName,domainId);
      if (userAccount != null) {
        permittedAccounts.add(userAccount.getId());
      }
 else {
        throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
      }
    }
  }
 else {
    permittedAccounts.add(caller.getId());
  }
  if (isRecursive == null) {
    isRecursive=false;
  }
  if (projectId != null) {
    permittedAccounts.clear();
    Project project=_projectMgr.getProject(projectId);
    if (project == null) {
      throw new InvalidParameterValueException("String_Node_Str" + projectId);
    }
    if (!_projectMgr.canAccessProjectAccount(caller,project.getProjectAccountId())) {
      throw new InvalidParameterValueException("String_Node_Str" + caller + "String_Node_Str"+ projectId);
    }
    permittedAccounts.add(project.getProjectAccountId());
  }
 else {
    permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
  }
  Object name=cmd.getSnapshotName();
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Object snapshotTypeStr=cmd.getSnapshotType();
  Object intervalTypeStr=cmd.getIntervalType();
  Filter searchFilter=new Filter(SnapshotVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<SnapshotVO> sb=_snapshotDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getStatus(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getVolumeId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getsnapshotType(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getsnapshotType(),SearchCriteria.Op.NEQ);
  if ((permittedAccounts.isEmpty()) && (domainId != null)) {
    SearchBuilder<AccountVO> accountSearch=_accountDao.createSearchBuilder();
    sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinType.INNER);
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    if (isRecursive) {
      domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    }
 else {
      domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.EQ);
    }
    accountSearch.join("String_Node_Str",domainSearch,accountSearch.entity().getDomainId(),domainSearch.entity().getId(),JoinType.INNER);
  }
  SearchCriteria<SnapshotVO> sc=sb.create();
  if (volumeId != null) {
    sc.setParameters("String_Node_Str",volumeId);
  }
  if (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (keyword != null) {
    SearchCriteria<SnapshotVO> ssc=_snapshotDao.createSearchCriteria();
    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 (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    SearchCriteria<?> joinSearch=sc.getJoin("String_Node_Str");
    if (isRecursive) {
      joinSearch.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      joinSearch.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath());
    }
  }
  if (snapshotTypeStr != null) {
    Type snapshotType=SnapshotVO.getSnapshotType((String)snapshotTypeStr);
    if (snapshotType == null) {
      throw new InvalidParameterValueException("String_Node_Str" + snapshotTypeStr);
    }
    if (snapshotType == Type.RECURRING) {
      sc.setParameters("String_Node_Str",Type.HOURLY.ordinal(),Type.DAILY.ordinal(),Type.WEEKLY.ordinal(),Type.MONTHLY.ordinal());
    }
 else {
      sc.setParameters("String_Node_Str",snapshotType.ordinal());
    }
  }
 else   if (intervalTypeStr != null && volumeId != null) {
    Type type=SnapshotVO.getSnapshotType((String)intervalTypeStr);
    if (type == null) {
      throw new InvalidParameterValueException("String_Node_Str" + intervalTypeStr);
    }
    sc.setParameters("String_Node_Str",type.ordinal());
  }
 else {
    sc.setParameters("String_Node_Str",Snapshot.Type.TEMPLATE.ordinal());
  }
  return _snapshotDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<SnapshotVO> listSnapshots(ListSnapshotsCmd cmd){
  Long volumeId=cmd.getVolumeId();
  Boolean isRecursive=cmd.isRecursive();
  Long projectId=cmd.getProjectId();
  if (volumeId != null) {
    VolumeVO volume=_volsDao.findById(volumeId);
    if (volume != null) {
      _accountMgr.checkAccess(UserContext.current().getCaller(),null,volume);
    }
  }
  Account caller=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  List<Long> permittedAccounts=new ArrayList<Long>();
  if ((caller == null) || _accountMgr.isAdmin(caller.getType())) {
    if (domainId != null) {
      if ((caller != null) && !_domainDao.isChildDomain(caller.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
    }
 else     if ((caller != null) && ((caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || (caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN))) {
      domainId=caller.getDomainId();
      isRecursive=true;
    }
    if (domainId != null && accountName != null) {
      Account userAccount=_accountDao.findActiveAccount(accountName,domainId);
      if (userAccount != null) {
        permittedAccounts.add(userAccount.getId());
      }
 else {
        throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
      }
    }
  }
 else {
    permittedAccounts.add(caller.getId());
  }
  if (isRecursive == null) {
    isRecursive=false;
  }
  boolean skipProjectSnapshots=true;
  if (projectId != null) {
    if (projectId == -1) {
      permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
    }
 else {
      permittedAccounts.clear();
      Project project=_projectMgr.getProject(projectId);
      if (project == null) {
        throw new InvalidParameterValueException("String_Node_Str" + projectId);
      }
      if (!_projectMgr.canAccessProjectAccount(caller,project.getProjectAccountId())) {
        throw new InvalidParameterValueException("String_Node_Str" + caller + "String_Node_Str"+ projectId);
      }
      permittedAccounts.add(project.getProjectAccountId());
    }
    skipProjectSnapshots=false;
  }
  Object name=cmd.getSnapshotName();
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Object snapshotTypeStr=cmd.getSnapshotType();
  Object intervalTypeStr=cmd.getIntervalType();
  Filter searchFilter=new Filter(SnapshotVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<SnapshotVO> sb=_snapshotDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getStatus(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getVolumeId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getsnapshotType(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getsnapshotType(),SearchCriteria.Op.NEQ);
  if ((permittedAccounts.isEmpty()) && (domainId != null)) {
    SearchBuilder<AccountVO> accountSearch=_accountDao.createSearchBuilder();
    sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinType.INNER);
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    if (isRecursive) {
      domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    }
 else {
      domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.EQ);
    }
    accountSearch.join("String_Node_Str",domainSearch,accountSearch.entity().getDomainId(),domainSearch.entity().getId(),JoinType.INNER);
  }
  if (skipProjectSnapshots) {
    SearchBuilder<AccountVO> accountSearch=_accountDao.createSearchBuilder();
    accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.NEQ);
    sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  SearchCriteria<SnapshotVO> sc=sb.create();
  if (skipProjectSnapshots) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  }
  if (volumeId != null) {
    sc.setParameters("String_Node_Str",volumeId);
  }
  if (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (keyword != null) {
    SearchCriteria<SnapshotVO> ssc=_snapshotDao.createSearchCriteria();
    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 (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    SearchCriteria<?> joinSearch=sc.getJoin("String_Node_Str");
    if (isRecursive) {
      joinSearch.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      joinSearch.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath());
    }
  }
  if (snapshotTypeStr != null) {
    Type snapshotType=SnapshotVO.getSnapshotType((String)snapshotTypeStr);
    if (snapshotType == null) {
      throw new InvalidParameterValueException("String_Node_Str" + snapshotTypeStr);
    }
    if (snapshotType == Type.RECURRING) {
      sc.setParameters("String_Node_Str",Type.HOURLY.ordinal(),Type.DAILY.ordinal(),Type.WEEKLY.ordinal(),Type.MONTHLY.ordinal());
    }
 else {
      sc.setParameters("String_Node_Str",snapshotType.ordinal());
    }
  }
 else   if (intervalTypeStr != null && volumeId != null) {
    Type type=SnapshotVO.getSnapshotType((String)intervalTypeStr);
    if (type == null) {
      throw new InvalidParameterValueException("String_Node_Str" + intervalTypeStr);
    }
    sc.setParameters("String_Node_Str",type.ordinal());
  }
 else {
    sc.setParameters("String_Node_Str",Snapshot.Type.TEMPLATE.ordinal());
  }
  return _snapshotDao.search(sc,searchFilter);
}