Program: 89649
Project: 89649
Buggy source:
@Override public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd){
  Account account=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  Long accountId=null;
  boolean isAdmin=false;
  Boolean isRecursive=cmd.isRecursive();
  if (isRecursive == null) {
    isRecursive=false;
  }
  if ((account == null) || isAdmin(account.getType())) {
    isAdmin=true;
    if (domainId != null) {
      if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
      if (accountName != null) {
        Account userAccount=_accountDao.findActiveAccount(accountName,domainId);
        if (userAccount != null) {
          accountId=userAccount.getId();
        }
 else {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
      }
    }
 else {
      domainId=((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
      isRecursive=true;
    }
  }
 else {
    accountId=account.getId();
  }
  Filter searchFilter=new Filter(VolumeVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  Object id=cmd.getId();
  Long vmInstanceId=cmd.getVirtualMachineId();
  Object name=cmd.getVolumeName();
  Object keyword=cmd.getKeyword();
  Object type=cmd.getType();
  Object zone=null;
  Object pod=null;
  if (isAdmin) {
    zone=cmd.getZoneId();
    pod=cmd.getPodId();
  }
 else {
    domainId=null;
  }
  SearchBuilder<VolumeVO> sb=_volumeDao.createSearchBuilder();
  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.EQ);
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getVolumeType(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getInstanceId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getDataCenterId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getPodId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.NEQ);
  SearchBuilder<DiskOfferingVO> diskOfferingSearch=_diskOfferingDao.createSearchBuilder();
  diskOfferingSearch.and("String_Node_Str",diskOfferingSearch.entity().isSystemUse(),SearchCriteria.Op.NEQ);
  sb.join("String_Node_Str",diskOfferingSearch,sb.entity().getDiskOfferingId(),diskOfferingSearch.entity().getId(),JoinBuilder.JoinType.LEFTOUTER);
  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);
  }
  SearchBuilder<VMInstanceVO> vmSearch=_vmInstanceDao.createSearchBuilder();
  vmSearch.and("String_Node_Str",vmSearch.entity().getType(),SearchCriteria.Op.NIN);
  sb.join("String_Node_Str",vmSearch,sb.entity().getInstanceId(),vmSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  SearchCriteria<VolumeVO> sc=sb.create();
  if (keyword != null) {
    SearchCriteria<VolumeVO> ssc=_volumeDao.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 (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",1);
  }
 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());
    }
  }
  if (type != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + type + "String_Node_Str");
  }
  if (vmInstanceId != null) {
    sc.setParameters("String_Node_Str",vmInstanceId);
  }
  if (zone != null) {
    sc.setParameters("String_Node_Str",zone);
  }
  if (pod != null) {
    sc.setParameters("String_Node_Str",pod);
  }
  sc.setJoinParameters("String_Node_Str","String_Node_Str",VirtualMachine.Type.ConsoleProxy,VirtualMachine.Type.SecondaryStorageVm,VirtualMachine.Type.DomainRouter);
  sc.setParameters("String_Node_Str",Volume.State.Destroy);
  return _volumeDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<VolumeVO> searchForVolumes(ListVolumesCmd cmd){
  Account account=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  Long accountId=null;
  boolean isAdmin=false;
  Boolean isRecursive=cmd.isRecursive();
  if (isRecursive == null) {
    isRecursive=false;
  }
  if ((account == null) || isAdmin(account.getType())) {
    isAdmin=true;
    if (domainId != null) {
      if ((account != null) && !_domainDao.isChildDomain(account.getDomainId(),domainId)) {
        throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
      }
      if (accountName != null) {
        Account userAccount=_accountDao.findActiveAccount(accountName,domainId);
        if (userAccount != null) {
          accountId=userAccount.getId();
        }
 else {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
      }
    }
 else {
      domainId=((account == null) ? DomainVO.ROOT_DOMAIN : account.getDomainId());
      isRecursive=true;
    }
  }
 else {
    accountId=account.getId();
  }
  Filter searchFilter=new Filter(VolumeVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  Object id=cmd.getId();
  Long vmInstanceId=cmd.getVirtualMachineId();
  Object name=cmd.getVolumeName();
  Object keyword=cmd.getKeyword();
  Object type=cmd.getType();
  Object zone=null;
  Object pod=null;
  if (isAdmin) {
    zone=cmd.getZoneId();
    pod=cmd.getPodId();
  }
 else {
    domainId=null;
  }
  SearchBuilder<VolumeVO> sb=_volumeDao.createSearchBuilder();
  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.EQ);
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getVolumeType(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getInstanceId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getDataCenterId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getPodId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.NEQ);
  SearchBuilder<DiskOfferingVO> diskOfferingSearch=_diskOfferingDao.createSearchBuilder();
  diskOfferingSearch.and("String_Node_Str",diskOfferingSearch.entity().isSystemUse(),SearchCriteria.Op.NEQ);
  sb.join("String_Node_Str",diskOfferingSearch,sb.entity().getDiskOfferingId(),diskOfferingSearch.entity().getId(),JoinBuilder.JoinType.LEFTOUTER);
  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);
  }
  SearchBuilder<VMInstanceVO> vmSearch=_vmInstanceDao.createSearchBuilder();
  vmSearch.and("String_Node_Str",vmSearch.entity().getType(),SearchCriteria.Op.NIN);
  vmSearch.or("String_Node_Str",vmSearch.entity().getType(),SearchCriteria.Op.NULL);
  sb.join("String_Node_Str",vmSearch,sb.entity().getInstanceId(),vmSearch.entity().getId(),JoinBuilder.JoinType.LEFTOUTER);
  SearchCriteria<VolumeVO> sc=sb.create();
  if (keyword != null) {
    SearchCriteria<VolumeVO> ssc=_volumeDao.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 (name != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + name + "String_Node_Str");
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (accountId != null) {
    sc.setParameters("String_Node_Str",accountId);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",1);
  }
 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());
    }
  }
  if (type != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + type + "String_Node_Str");
  }
  if (vmInstanceId != null) {
    sc.setParameters("String_Node_Str",vmInstanceId);
  }
  if (zone != null) {
    sc.setParameters("String_Node_Str",zone);
  }
  if (pod != null) {
    sc.setParameters("String_Node_Str",pod);
  }
  sc.setJoinParameters("String_Node_Str","String_Node_Str",VirtualMachine.Type.ConsoleProxy,VirtualMachine.Type.SecondaryStorageVm,VirtualMachine.Type.DomainRouter);
  sc.setParameters("String_Node_Str",Volume.State.Destroy);
  return _volumeDao.search(sc,searchFilter);
}