Program: 89155
Project: 89155
Buggy source:
@Override public List<? extends NetworkOffering> 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,cmd.getStartIndex(),cmd.getPageSizeVal());
  Account caller=UserContext.current().getCaller();
  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();
  if (zoneId != null) {
    zone=getZone(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 ArrayList<NetworkOffering>();
    }
  }
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,false);
  if (networkId != null) {
    Network network=_networkMgr.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=_networkMgr.listNetworkOfferingsForUpgrade(networkId);
    if (!offeringIds.isEmpty()) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.IN,offeringIds.toArray());
    }
 else {
      return new ArrayList<NetworkOffering>();
    }
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  List<NetworkOfferingVO> offerings=_networkOfferingDao.search(sc,searchFilter);
  Boolean sourceNatSupported=cmd.getSourceNatSupported();
  boolean listBySupportedServices=(supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
  boolean checkIfProvidersAreEnabled=(zoneId != null);
  boolean parseOfferings=(listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled);
  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 (listBySupportedServices) {
        addOffering=addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(),supportedServices);
      }
      if (checkIfProvidersAreEnabled) {
        if (supportedServices != null && supportedServices.length > 0) {
          checkForProviders=Arrays.asList(supportedServices);
        }
 else {
          checkForProviders=_networkMgr.listNetworkOfferingServices(offering.getId());
        }
        addOffering=addOffering && _networkMgr.areServicesEnabledInZone(zoneId,offering.getId(),offering.getTags(),checkForProviders);
      }
      if (sourceNatSupported != null) {
        addOffering=addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(),Network.Service.SourceNat) == sourceNatSupported);
      }
      if (addOffering) {
        supportedOfferings.add(offering);
      }
    }
    return supportedOfferings;
  }
 else {
    return offerings;
  }
}

Fixed version (ground truth):
@Override public List<? extends NetworkOffering> 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,cmd.getStartIndex(),cmd.getPageSizeVal());
  Account caller=UserContext.current().getCaller();
  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();
  if (zoneId != null) {
    zone=getZone(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 ArrayList<NetworkOffering>();
    }
  }
  sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,false);
  if (networkId != null) {
    Network network=_networkMgr.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=_networkMgr.listNetworkOfferingsForUpgrade(networkId);
    if (!offeringIds.isEmpty()) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.IN,offeringIds.toArray());
    }
 else {
      return new ArrayList<NetworkOffering>();
    }
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  List<NetworkOfferingVO> offerings=_networkOfferingDao.search(sc,searchFilter);
  Boolean sourceNatSupported=cmd.getSourceNatSupported();
  boolean listBySupportedServices=(supportedServicesStr != null && !supportedServicesStr.isEmpty() && !offerings.isEmpty());
  boolean checkIfProvidersAreEnabled=(zoneId != null);
  boolean parseOfferings=(listBySupportedServices || sourceNatSupported != null || checkIfProvidersAreEnabled);
  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 (listBySupportedServices) {
        addOffering=addOffering && _networkMgr.areServicesSupportedByNetworkOffering(offering.getId(),supportedServices);
      }
      if (checkIfProvidersAreEnabled) {
        if (supportedServices != null && supportedServices.length > 0) {
          checkForProviders=Arrays.asList(supportedServices);
        }
 else {
          checkForProviders=_networkMgr.listNetworkOfferingServices(offering.getId());
        }
        addOffering=addOffering && _networkMgr.areServicesEnabledInZone(zoneId,offering,checkForProviders);
      }
      if (sourceNatSupported != null) {
        addOffering=addOffering && (_networkMgr.areServicesSupportedByNetworkOffering(offering.getId(),Network.Service.SourceNat) == sourceNatSupported);
      }
      if (addOffering) {
        supportedOfferings.add(offering);
      }
    }
    return supportedOfferings;
  }
 else {
    return offerings;
  }
}