Program: 89340
Project: 89340
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 type=cmd.getType();
  String trafficType=cmd.getTrafficType();
  Boolean isSystem=cmd.getIsSystem();
  Boolean isShared=cmd.getIsShared();
  Boolean isDefault=cmd.isDefault();
  Long accountId=null;
  String path=null;
  Long sharedNetworkDomainId=null;
  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 (_accountMgr.isAdmin(caller.getType())) {
    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.getActiveAccount(accountName,domainId);
        if (owner == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=owner.getId();
      }
    }
    DomainVO domain=_domainDao.findById(caller.getDomainId());
    path=domain.getPath();
  }
 else {
    accountId=caller.getId();
  }
  if ((isSystem == null || !isSystem) && (isShared == null || isShared)) {
    sharedNetworkDomainId=domainId;
  }
  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);
  if (sharedNetworkDomainId != null) {
    SearchBuilder<NetworkDomainVO> domainNetworkSearch=_networkDomainDao.createSearchBuilder();
    sb.join("String_Node_Str",domainNetworkSearch,sb.entity().getId(),domainNetworkSearch.entity().getNetworkId(),JoinBuilder.JoinType.LEFTOUTER);
  }
  sb.and("String_Node_Str",sb.entity().getRemoved(),Op.NULL);
  if (isSystem == null || !isSystem) {
    List<NetworkVO> networksToReturn=new ArrayList<NetworkVO>();
    if (sharedNetworkDomainId != null) {
      networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,sharedNetworkDomainId));
    }
 else {
      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);
      networksToReturn.addAll(listDomainSpecificNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,path));
    }
    if (accountId != null || (domainId == null && accountName == null)) {
      networksToReturn.addAll(listAccountSpecificAndZoneLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,accountId,path));
    }
    return networksToReturn;
  }
 else {
    return _networksDao.search(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter);
  }
}

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 type=cmd.getType();
  String trafficType=cmd.getTrafficType();
  Boolean isSystem=cmd.getIsSystem();
  Boolean isShared=cmd.getIsShared();
  Boolean isDefault=cmd.isDefault();
  Long accountId=null;
  String path=null;
  Long sharedNetworkDomainId=null;
  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");
  }
  DomainVO domain=null;
  if (domainId != null) {
    domain=_domainDao.findById(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId + "String_Node_Str");
    }
    _accountMgr.checkAccess(caller,domain);
  }
  if (_accountMgr.isAdmin(caller.getType())) {
    if (domainId != null) {
      if (accountName != null) {
        Account owner=_accountMgr.getActiveAccount(accountName,domainId);
        if (owner == null) {
          throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId);
        }
        accountId=owner.getId();
      }
    }
  }
 else {
    accountId=caller.getId();
  }
  path=_domainDao.findById(caller.getDomainId()).getPath();
  if (domainId == null) {
    domainId=caller.getDomainId();
  }
  if ((isSystem == null || !isSystem) && (isShared == null || isShared)) {
    sharedNetworkDomainId=domainId;
  }
  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);
  if (sharedNetworkDomainId != null) {
    SearchBuilder<NetworkDomainVO> domainNetworkSearch=_networkDomainDao.createSearchBuilder();
    sb.join("String_Node_Str",domainNetworkSearch,sb.entity().getId(),domainNetworkSearch.entity().getNetworkId(),JoinBuilder.JoinType.LEFTOUTER);
  }
  sb.and("String_Node_Str",sb.entity().getRemoved(),Op.NULL);
  if (isSystem == null || !isSystem) {
    List<NetworkVO> networksToReturn=new ArrayList<NetworkVO>();
    if (sharedNetworkDomainId != null) {
      networksToReturn.addAll(listDomainLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,sharedNetworkDomainId));
    }
 else {
      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);
      networksToReturn.addAll(listDomainSpecificNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,path));
    }
    if (!(isShared != null && isShared && cmd.getDomainId() != null) && (accountId != null || (domainId == null && accountName == null))) {
      networksToReturn.addAll(listAccountSpecificAndZoneLevelNetworks(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter,accountId,path));
    }
    return networksToReturn;
  }
 else {
    return _networksDao.search(buildNetworkSearchCriteria(sb,keyword,id,isSystem,zoneId,type,isDefault,trafficType,isShared),searchFilter);
  }
}