Program: 105493
Project: 105493
Buggy source:
@Override public Pair<List<? extends NetworkOffering>,Integer> searchForNetworkOfferings(ListNetworkOfferingsCmd cmd){
  Boolean isAscending=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  isAscending=(isAscending == null ? true : isAscending);
  Filter searchFilter=new Filter(NetworkOfferingVO.class,"String_Node_Str",isAscending,null,null);
  Account caller=CallContext.current().getCallingAccount();
  SearchCriteria<NetworkOfferingVO> sc=_networkOfferingDao.createSearchCriteria();
  Long id=cmd.getId();
  Object name=cmd.getNetworkOfferingName();
  Object displayText=cmd.getDisplayText();
  Object trafficType=cmd.getTrafficType();
  Object isDefault=cmd.getIsDefault();
  Object specifyVlan=cmd.getSpecifyVlan();
  Object availability=cmd.getAvailability();
  Object state=cmd.getState();
  Long zoneId=cmd.getZoneId();
  DataCenter zone=null;
  Long networkId=cmd.getNetworkId();
  String guestIpType=cmd.getGuestIpType();
  List<String> supportedServicesStr=cmd.getSupportedServices();
  Object specifyIpRanges=cmd.getSpecifyIpRanges();
  String tags=cmd.getTags();
  Boolean isTagged=cmd.isTagged();
  Boolean forVpc=cmd.getForVpc();
  if (zoneId != null) {
    zone=_entityMgr.findById(DataCenter.class,zoneId);
    if (zone == null) {
      throw new InvalidParameterValueException("String_Node_Str" + zoneId);
    }
  }
  Object keyword=cmd.getKeyword();
  if (keyword != null) {
    SearchCriteria<NetworkOfferingVO> ssc=_networkOfferingDao.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.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + name + "String_Node_Str");
  }
  if (guestIpType != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,guestIpType);
  }
  if (displayText != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + displayText + "String_Node_Str");
  }
  if (trafficType != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,trafficType);
  }
  if (isDefault != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,isDefault);
  }
  if (specifyVlan != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,specifyVlan);
  }
  if (availability != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,availability);
  }
  if (state != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,state);
  }
  if (specifyIpRanges != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,specifyIpRanges);
  }
  if (zone != null) {
    if (zone.getNetworkType() == NetworkType.Basic) {
      return new Pair<List<? extends NetworkOffering>,Integer>(new ArrayList<NetworkOffering>(),0);
    }
  }
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,false);
  Network network=null;
  if (networkId != null) {
    network=_networkModel.getNetwork(networkId);
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkId);
    }
    NetworkOffering offering=_networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
    if (offering.isSystemOnly()) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    _accountMgr.checkAccess(caller,null,true,network);
    List<Long> offeringIds=_networkModel.listNetworkOfferingsForUpgrade(networkId);
    if (!offeringIds.isEmpty()) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.IN,offeringIds.toArray());
    }
 else {
      return new Pair<List<? extends NetworkOffering>,Integer>(new ArrayList<NetworkOffering>(),0);
    }
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (tags != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,tags);
  }
  if (isTagged != null) {
    if (isTagged) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.NNULL);
    }
 else {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.NULL);
    }
  }
  List<NetworkOfferingVO> offerings=_networkOfferingDao.search(sc,searchFilter);
  Boolean sourceNatSupported=cmd.getSourceNatSupported();
  List<String> pNtwkTags=new ArrayList<String>();
  boolean checkForTags=false;
  if (zone != null) {
    List<PhysicalNetworkVO> pNtwks=_physicalNetworkDao.listByZoneAndTrafficType(zoneId,TrafficType.Guest);
    if (pNtwks.size() > 1) {
      checkForTags=true;
      for (      PhysicalNetworkVO pNtwk : pNtwks) {
        List<String> pNtwkTag=pNtwk.getTags();
        if (pNtwkTag == null || pNtwkTag.isEmpty()) {
          throw new CloudRuntimeException("String_Node_Str" + zoneId);
        }
        pNtwkTags.addAll(pNtwkTag);
      }
    }
  }
  boolean listBySupportedServices=(supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
  boolean checkIfProvidersAreEnabled=(zoneId != null);
  boolean parseOfferings=(listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null);
  if (parseOfferings) {
    List<NetworkOfferingVO> supportedOfferings=new ArrayList<NetworkOfferingVO>();
    Service[] supportedServices=null;
    if (listBySupportedServices) {
      supportedServices=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 {
          supportedServices[i]=service;
        }
        i++;
      }
    }
    for (    NetworkOfferingVO offering : offerings) {
      boolean addOffering=true;
      List<Service> checkForProviders=new ArrayList<Service>();
      if (checkForTags) {
        if (!pNtwkTags.contains(offering.getTags())) {
          continue;
        }
      }
      if (listBySupportedServices) {
        addOffering=addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(),supportedServices);
      }
      if (checkIfProvidersAreEnabled) {
        if (supportedServices != null && supportedServices.length > 0) {
          checkForProviders=Arrays.asList(supportedServices);
        }
 else {
          checkForProviders=_networkModel.listNetworkOfferingServices(offering.getId());
        }
        addOffering=addOffering && _networkModel.areServicesEnabledInZone(zoneId,offering,checkForProviders);
      }
      if (sourceNatSupported != null) {
        addOffering=addOffering && (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(),Network.Service.SourceNat) == sourceNatSupported);
      }
      if (forVpc != null) {
        addOffering=addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue());
      }
 else       if (network != null) {
        addOffering=addOffering && (isOfferingForVpc(offering) == (network.getVpcId() != null));
      }
      if (addOffering) {
        supportedOfferings.add(offering);
      }
    }
    List<? extends NetworkOffering> wPagination=StringUtils.applyPagination(supportedOfferings,cmd.getStartIndex(),cmd.getPageSizeVal());
    if (wPagination != null) {
      Pair<List<? extends NetworkOffering>,Integer> listWPagination=new Pair<List<? extends NetworkOffering>,Integer>(wPagination,offerings.size());
      return listWPagination;
    }
    return new Pair<List<? extends NetworkOffering>,Integer>(supportedOfferings,supportedOfferings.size());
  }
 else {
    List<? extends NetworkOffering> wPagination=StringUtils.applyPagination(offerings,cmd.getStartIndex(),cmd.getPageSizeVal());
    if (wPagination != null) {
      Pair<List<? extends NetworkOffering>,Integer> listWPagination=new Pair<List<? extends NetworkOffering>,Integer>(wPagination,offerings.size());
      return listWPagination;
    }
    return new Pair<List<? extends NetworkOffering>,Integer>(offerings,offerings.size());
  }
}

Fixed version (ground truth):
@Override public Pair<List<? extends NetworkOffering>,Integer> searchForNetworkOfferings(ListNetworkOfferingsCmd cmd){
  Boolean isAscending=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  isAscending=(isAscending == null ? Boolean.TRUE : isAscending);
  Filter searchFilter=new Filter(NetworkOfferingVO.class,"String_Node_Str",isAscending,null,null);
  Account caller=CallContext.current().getCallingAccount();
  SearchCriteria<NetworkOfferingVO> sc=_networkOfferingDao.createSearchCriteria();
  Long id=cmd.getId();
  Object name=cmd.getNetworkOfferingName();
  Object displayText=cmd.getDisplayText();
  Object trafficType=cmd.getTrafficType();
  Object isDefault=cmd.getIsDefault();
  Object specifyVlan=cmd.getSpecifyVlan();
  Object availability=cmd.getAvailability();
  Object state=cmd.getState();
  Long zoneId=cmd.getZoneId();
  DataCenter zone=null;
  Long networkId=cmd.getNetworkId();
  String guestIpType=cmd.getGuestIpType();
  List<String> supportedServicesStr=cmd.getSupportedServices();
  Object specifyIpRanges=cmd.getSpecifyIpRanges();
  String tags=cmd.getTags();
  Boolean isTagged=cmd.isTagged();
  Boolean forVpc=cmd.getForVpc();
  if (zoneId != null) {
    zone=_entityMgr.findById(DataCenter.class,zoneId);
    if (zone == null) {
      throw new InvalidParameterValueException("String_Node_Str" + zoneId);
    }
  }
  Object keyword=cmd.getKeyword();
  if (keyword != null) {
    SearchCriteria<NetworkOfferingVO> ssc=_networkOfferingDao.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.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + name + "String_Node_Str");
  }
  if (guestIpType != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,guestIpType);
  }
  if (displayText != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + displayText + "String_Node_Str");
  }
  if (trafficType != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,trafficType);
  }
  if (isDefault != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,isDefault);
  }
  if (specifyVlan != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,specifyVlan);
  }
  if (availability != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,availability);
  }
  if (state != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,state);
  }
  if (specifyIpRanges != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,specifyIpRanges);
  }
  if (zone != null) {
    if (zone.getNetworkType() == NetworkType.Basic) {
      return new Pair<List<? extends NetworkOffering>,Integer>(new ArrayList<NetworkOffering>(),0);
    }
  }
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,false);
  Network network=null;
  if (networkId != null) {
    network=_networkModel.getNetwork(networkId);
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkId);
    }
    NetworkOffering offering=_networkOfferingDao.findByIdIncludingRemoved(network.getNetworkOfferingId());
    if (offering.isSystemOnly()) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    _accountMgr.checkAccess(caller,null,true,network);
    List<Long> offeringIds=_networkModel.listNetworkOfferingsForUpgrade(networkId);
    if (!offeringIds.isEmpty()) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.IN,offeringIds.toArray());
    }
 else {
      return new Pair<List<? extends NetworkOffering>,Integer>(new ArrayList<NetworkOffering>(),0);
    }
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (tags != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,tags);
  }
  if (isTagged != null) {
    if (isTagged) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.NNULL);
    }
 else {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.NULL);
    }
  }
  List<NetworkOfferingVO> offerings=_networkOfferingDao.search(sc,searchFilter);
  Boolean sourceNatSupported=cmd.getSourceNatSupported();
  List<String> pNtwkTags=new ArrayList<String>();
  boolean checkForTags=false;
  if (zone != null) {
    List<PhysicalNetworkVO> pNtwks=_physicalNetworkDao.listByZoneAndTrafficType(zoneId,TrafficType.Guest);
    if (pNtwks.size() > 1) {
      checkForTags=true;
      for (      PhysicalNetworkVO pNtwk : pNtwks) {
        List<String> pNtwkTag=pNtwk.getTags();
        if (pNtwkTag == null || pNtwkTag.isEmpty()) {
          throw new CloudRuntimeException("String_Node_Str" + zoneId);
        }
        pNtwkTags.addAll(pNtwkTag);
      }
    }
  }
  boolean listBySupportedServices=(supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
  boolean checkIfProvidersAreEnabled=(zoneId != null);
  boolean parseOfferings=(listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled || forVpc != null || network != null);
  if (parseOfferings) {
    List<NetworkOfferingVO> supportedOfferings=new ArrayList<NetworkOfferingVO>();
    Service[] supportedServices=null;
    if (listBySupportedServices) {
      supportedServices=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 {
          supportedServices[i]=service;
        }
        i++;
      }
    }
    for (    NetworkOfferingVO offering : offerings) {
      boolean addOffering=true;
      List<Service> checkForProviders=new ArrayList<Service>();
      if (checkForTags) {
        if (!pNtwkTags.contains(offering.getTags())) {
          continue;
        }
      }
      if (listBySupportedServices) {
        addOffering=addOffering && _networkModel.areServicesSupportedByNetworkOffering(offering.getId(),supportedServices);
      }
      if (checkIfProvidersAreEnabled) {
        if (supportedServices != null && supportedServices.length > 0) {
          checkForProviders=Arrays.asList(supportedServices);
        }
 else {
          checkForProviders=_networkModel.listNetworkOfferingServices(offering.getId());
        }
        addOffering=addOffering && _networkModel.areServicesEnabledInZone(zoneId,offering,checkForProviders);
      }
      if (sourceNatSupported != null) {
        addOffering=addOffering && (_networkModel.areServicesSupportedByNetworkOffering(offering.getId(),Network.Service.SourceNat) == sourceNatSupported);
      }
      if (forVpc != null) {
        addOffering=addOffering && (isOfferingForVpc(offering) == forVpc.booleanValue());
      }
 else       if (network != null) {
        addOffering=addOffering && (isOfferingForVpc(offering) == (network.getVpcId() != null));
      }
      if (addOffering) {
        supportedOfferings.add(offering);
      }
    }
    List<? extends NetworkOffering> wPagination=StringUtils.applyPagination(supportedOfferings,cmd.getStartIndex(),cmd.getPageSizeVal());
    if (wPagination != null) {
      Pair<List<? extends NetworkOffering>,Integer> listWPagination=new Pair<List<? extends NetworkOffering>,Integer>(wPagination,offerings.size());
      return listWPagination;
    }
    return new Pair<List<? extends NetworkOffering>,Integer>(supportedOfferings,supportedOfferings.size());
  }
 else {
    List<? extends NetworkOffering> wPagination=StringUtils.applyPagination(offerings,cmd.getStartIndex(),cmd.getPageSizeVal());
    if (wPagination != null) {
      Pair<List<? extends NetworkOffering>,Integer> listWPagination=new Pair<List<? extends NetworkOffering>,Integer>(wPagination,offerings.size());
      return listWPagination;
    }
    return new Pair<List<? extends NetworkOffering>,Integer>(offerings,offerings.size());
  }
}