Program: 89243
Project: 89243
Buggy source:
@Override public List<? extends Network> searchForNetworks(ListNetworksCmd cmd){
  Long id=cmd.getId();
  String keyword=cmd.getKeyword();
  Long zoneId=cmd.getZoneId();
  Account caller=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  String guestIpType=cmd.getGuestIpType();
  String trafficType=cmd.getTrafficType();
  Boolean isSystem=cmd.getIsSystem();
  String aclType=cmd.getAclType();
  Long projectId=cmd.getProjectId();
  List<Long> permittedAccounts=new ArrayList<Long>();
  String path=null;
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  List<String> supportedServicesStr=cmd.getSupportedServices();
  if ((isSystem == null || caller.getType() == Account.ACCOUNT_TYPE_NORMAL) && id == null) {
    isSystem=false;
  }
  if (isSystem != null && isSystem && (accountName != null || domainId != null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (domainId != null) {
    DomainVO 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 owner=_accountMgr.getActiveAccountByName(accountName,domainId);
      if (owner == null) {
        throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
      }
      _accountMgr.checkAccess(caller,null,owner);
      permittedAccounts.add(owner.getId());
    }
  }
  if (!_accountMgr.isAdmin(caller.getType())) {
    permittedAccounts.add(caller.getId());
    domainId=caller.getDomainId();
  }
  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   if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
    permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
  }
  path=_domainDao.findById(caller.getDomainId()).getPath();
  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 != null && 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);
  sb.and("String_Node_Str",sb.entity().getRemoved(),Op.NULL);
  if (permittedAccounts.isEmpty()) {
    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);
  }
  List<NetworkVO> networksToReturn=new ArrayList<NetworkVO>();
  if (isSystem == null || !isSystem) {
    if (domainId != null) {
      networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType),searchFilter,domainId));
    }
 else     if (permittedAccounts.isEmpty()) {
      networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType),searchFilter,path));
    }
    if (!permittedAccounts.isEmpty()) {
      networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType),searchFilter,permittedAccounts));
    }
  }
 else {
    networksToReturn=_networksDao.search(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,null),searchFilter);
  }
  if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
    List<NetworkVO> supportedNetworks=new ArrayList<NetworkVO>();
    Service[] suppportedServices=new Service[supportedServicesStr.size()];
    int i=0;
    for (    String supportedServiceStr : supportedServicesStr) {
      Service service=Service.getService(supportedServiceStr);
      if (service == null) {
        throw new InvalidParameterValueException("String_Node_Str" + supportedServiceStr);
      }
 else {
        suppportedServices[i]=service;
      }
      i++;
    }
    for (    NetworkVO network : networksToReturn) {
      if (areServicesSupportedInNetwork(network.getId(),suppportedServices)) {
        supportedNetworks.add(network);
      }
    }
    return supportedNetworks;
  }
 else {
    return networksToReturn;
  }
}

Fixed version (ground truth):
@Override public List<? extends Network> searchForNetworks(ListNetworksCmd cmd){
  Long id=cmd.getId();
  String keyword=cmd.getKeyword();
  Long zoneId=cmd.getZoneId();
  Account caller=UserContext.current().getCaller();
  Long domainId=cmd.getDomainId();
  String accountName=cmd.getAccountName();
  String guestIpType=cmd.getGuestIpType();
  String trafficType=cmd.getTrafficType();
  Boolean isSystem=cmd.getIsSystem();
  String aclType=cmd.getAclType();
  Long projectId=cmd.getProjectId();
  List<Long> permittedAccounts=new ArrayList<Long>();
  String path=null;
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  List<String> supportedServicesStr=cmd.getSupportedServices();
  if ((isSystem == null || caller.getType() == Account.ACCOUNT_TYPE_NORMAL) && id == null) {
    isSystem=false;
  }
  if (isSystem != null && isSystem && (accountName != null || domainId != null)) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (domainId != null) {
    DomainVO 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 owner=_accountMgr.getActiveAccountByName(accountName,domainId);
      if (owner == null) {
        throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
      }
      _accountMgr.checkAccess(caller,null,owner);
      permittedAccounts.add(owner.getId());
    }
  }
  if (!_accountMgr.isAdmin(caller.getType())) {
    permittedAccounts.add(caller.getId());
    domainId=caller.getDomainId();
  }
  boolean skipProjectNetworks=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());
    }
    skipProjectNetworks=false;
  }
  path=_domainDao.findById(caller.getDomainId()).getPath();
  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 != null && 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);
  sb.and("String_Node_Str",sb.entity().getRemoved(),Op.NULL);
  if (permittedAccounts.isEmpty()) {
    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);
  }
  if (skipProjectNetworks) {
    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);
  }
  List<NetworkVO> networksToReturn=new ArrayList<NetworkVO>();
  if (isSystem == null || !isSystem) {
    if (domainId != null) {
      networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType,skipProjectNetworks),searchFilter,domainId));
    }
 else     if (permittedAccounts.isEmpty()) {
      networksToReturn.addAll(listAccountSpecificNetworksByDomainPath(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType,skipProjectNetworks),searchFilter,path));
    }
    if (!permittedAccounts.isEmpty()) {
      networksToReturn.addAll(listAccountSpecificNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,aclType,skipProjectNetworks),searchFilter,permittedAccounts));
    }
  }
 else {
    networksToReturn=_networksDao.search(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,guestIpType,trafficType,physicalNetworkId,null,skipProjectNetworks),searchFilter);
  }
  if (supportedServicesStr != null && !supportedServicesStr.isEmpty() && !networksToReturn.isEmpty()) {
    List<NetworkVO> supportedNetworks=new ArrayList<NetworkVO>();
    Service[] suppportedServices=new Service[supportedServicesStr.size()];
    int i=0;
    for (    String supportedServiceStr : supportedServicesStr) {
      Service service=Service.getService(supportedServiceStr);
      if (service == null) {
        throw new InvalidParameterValueException("String_Node_Str" + supportedServiceStr);
      }
 else {
        suppportedServices[i]=service;
      }
      i++;
    }
    for (    NetworkVO network : networksToReturn) {
      if (areServicesSupportedInNetwork(network.getId(),suppportedServices)) {
        supportedNetworks.add(network);
      }
    }
    return supportedNetworks;
  }
 else {
    return networksToReturn;
  }
}