Program: 107248
Project: 107248
Buggy source:
@Override public List<? extends Network> searchForNetworks(ListNetworksCmd cmd){
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Long zoneId=cmd.getZoneId();
  Account account=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  String type=cmd.getType();
  Boolean isSystem=cmd.getIsSystem();
  Long accountId=null;
  if (isSystem == null) {
    isSystem=false;
  }
  if (isAdmin(account.getType())) {
    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=_accountDao.findActiveAccount(accountName,domainId);
        if (account == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=account.getId();
      }
    }
 else {
      accountId=account.getId();
    }
  }
 else {
    accountId=account.getId();
  }
  Filter searchFilter=new Filter(NetworkVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<NetworkVO> sb=_networksDao.createSearchBuilder();
  SearchBuilder<NetworkOfferingVO> networkOfferingSearch=_networkOfferingDao.createSearchBuilder();
  networkOfferingSearch.and("String_Node_Str",networkOfferingSearch.entity().isSystemOnly(),SearchCriteria.Op.EQ);
  if (isSystem) {
    networkOfferingSearch.and("String_Node_Str",networkOfferingSearch.entity().getTrafficType(),SearchCriteria.Op.EQ);
  }
  sb.join("String_Node_Str",networkOfferingSearch,sb.entity().getNetworkOfferingId(),networkOfferingSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  SearchBuilder<DataCenterVO> zoneSearch=_dcDao.createSearchBuilder();
  zoneSearch.and("String_Node_Str",zoneSearch.entity().getNetworkType(),SearchCriteria.Op.EQ);
  sb.join("String_Node_Str",zoneSearch,sb.entity().getDataCenterId(),zoneSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  SearchCriteria<NetworkVO> sc=sb.create();
  if (!isSystem) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",false);
  }
 else {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",true);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",TrafficType.Public);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",NetworkType.Advanced.toString());
  }
  if (keyword != null) {
    SearchCriteria<NetworkVO> ssc=_networksDao.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 (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (zoneId != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,zoneId);
  }
  if (type != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,type);
  }
  SearchCriteria<NetworkVO> ssc=_networksDao.createSearchCriteria();
  ssc.addOr("String_Node_Str",SearchCriteria.Op.EQ,accountId);
  if (accountName == null && domainId == null) {
    ssc.addOr("String_Node_Str",SearchCriteria.Op.EQ,1L);
  }
  sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,ssc);
  List<NetworkVO> networks=_networksDao.search(sc,searchFilter);
  return networks;
}

Fixed version (ground truth):
@Override public List<? extends Network> searchForNetworks(ListNetworksCmd cmd){
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Long zoneId=cmd.getZoneId();
  Account account=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  String type=cmd.getType();
  Boolean isSystem=cmd.getIsSystem();
  Long accountId=null;
  if (isSystem == null) {
    isSystem=false;
  }
  if (isAdmin(account.getType())) {
    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=_accountDao.findActiveAccount(accountName,domainId);
        if (account == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=account.getId();
      }
    }
 else {
      accountId=account.getId();
    }
  }
 else {
    accountId=account.getId();
  }
  Filter searchFilter=new Filter(NetworkVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<NetworkVO> sb=_networksDao.createSearchBuilder();
  SearchBuilder<NetworkOfferingVO> networkOfferingSearch=_networkOfferingDao.createSearchBuilder();
  networkOfferingSearch.and("String_Node_Str",networkOfferingSearch.entity().isSystemOnly(),SearchCriteria.Op.EQ);
  if (isSystem) {
    networkOfferingSearch.and("String_Node_Str",networkOfferingSearch.entity().getTrafficType(),SearchCriteria.Op.EQ);
  }
  sb.join("String_Node_Str",networkOfferingSearch,sb.entity().getNetworkOfferingId(),networkOfferingSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  SearchBuilder<DataCenterVO> zoneSearch=_dcDao.createSearchBuilder();
  zoneSearch.and("String_Node_Str",zoneSearch.entity().getNetworkType(),SearchCriteria.Op.EQ);
  sb.join("String_Node_Str",zoneSearch,sb.entity().getDataCenterId(),zoneSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  SearchCriteria<NetworkVO> sc=sb.create();
  if (!isSystem) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",false);
  }
 else {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",true);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",TrafficType.Public);
    sc.setJoinParameters("String_Node_Str","String_Node_Str",NetworkType.Advanced.toString());
  }
  if (keyword != null) {
    SearchCriteria<NetworkVO> ssc=_networksDao.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 (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (zoneId != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,zoneId);
  }
  if (type != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,type);
  }
  if (account.getType() != Account.ACCOUNT_TYPE_ADMIN || (accountName != null && domainId != null)) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,accountId);
  }
  SearchCriteria<NetworkVO> ssc=_networksDao.createSearchCriteria();
  List<NetworkVO> networks=_networksDao.search(sc,searchFilter);
  return networks;
}