Program: 3941
Project: 3941
Buggy source:
/** 
 * Gets user or domain settings using Autodiscover SOAP service.
 * @param < TGetSettingsResponseCollection > the generic type
 * @param < TSettingName >                   the generic type
 * @param cls                              the cls
 * @param cls1                             the cls1
 * @param identities                       Either the domains or the SMTP addresses of the users.
 * @param settings                         The settings.
 * @param requestedVersion                 Requested version of the Exchange service.
 * @param getSettingsMethod                The method to use.
 * @param getDomainMethod                  The method to calculate the domain value.
 * @return TGetSettingsResponse Collection.
 * @throws Exception the exception
 */
private <TGetSettingsResponseCollection,TSettingName>TGetSettingsResponseCollection getSettings(Class<TGetSettingsResponseCollection> cls,Class<TSettingName> cls1,List<String> identities,List<TSettingName> settings,ExchangeVersion requestedVersion,IFunctionDelegate<List<String>,List<TSettingName>,TGetSettingsResponseCollection> getSettingsMethod,IFuncDelegate<String> getDomainMethod) throws Exception {
  TGetSettingsResponseCollection response;
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    throw new ServiceVersionException(String.format(Strings.AutodiscoverServiceIncompatibleWithRequestVersion,MinimumRequestVersionForAutoDiscoverSoapService));
  }
  if (this.url != null) {
    URI autodiscoverUrl=this.url;
    response=getSettingsMethod.func(identities,settings,requestedVersion,this.url);
    this.url=autodiscoverUrl;
    return response;
  }
 else   if (!(this.domain == null || this.domain.isEmpty())) {
    URI autodiscoverUrl=this.getAutodiscoverEndpointUrl(this.domain);
    response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
    this.url=autodiscoverUrl;
    return response;
  }
 else {
    this.isExternal=true;
    URI autodiscoverUrl;
    String domainName=getDomainMethod.func();
    int scpHostCount;
    OutParam<Integer> outParam=new OutParam<Integer>();
    List<String> hosts=this.getAutodiscoverServiceHosts(domainName,outParam);
    scpHostCount=outParam.getParam();
    if (hosts.size() == 0) {
      throw new ServiceValidationException(Strings.AutodiscoverServiceRequestRequiresDomainOrUrl);
    }
    for (int currentHostIndex=0; currentHostIndex < hosts.size(); currentHostIndex++) {
      String host=hosts.get(currentHostIndex);
      boolean isScpHost=currentHostIndex < scpHostCount;
      OutParam<URI> outParams=new OutParam<URI>();
      if (this.tryGetAutodiscoverEndpointUrl(host,outParams)) {
        autodiscoverUrl=outParams.getParam();
        response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
        this.url=autodiscoverUrl;
        if (isScpHost) {
          this.isExternal=false;
        }
        return response;
      }
    }
    autodiscoverUrl=this.getRedirectUrl(domainName);
    OutParam<URI> outParamUrl=new OutParam<URI>();
    if ((autodiscoverUrl != null) && this.callRedirectionUrlValidationCallback(autodiscoverUrl.toString()) && this.tryGetAutodiscoverEndpointUrl(autodiscoverUrl.getHost(),outParamUrl)) {
      autodiscoverUrl=outParamUrl.getParam();
      response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
      this.url=autodiscoverUrl;
      return response;
    }
    autodiscoverUrl=this.getRedirectionUrlFromDnsSrvRecord(domainName);
    if ((autodiscoverUrl != null) && this.callRedirectionUrlValidationCallback(autodiscoverUrl.toString()) && this.tryGetAutodiscoverEndpointUrl(autodiscoverUrl.getHost(),outParamUrl)) {
      autodiscoverUrl=outParamUrl.getParam();
      response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
      this.url=autodiscoverUrl;
      return response;
    }
 else {
      throw new AutodiscoverLocalException(Strings.AutodiscoverCouldNotBeLocated);
    }
  }
}

Fixed version (ground truth):
/** 
 * Gets user or domain settings using Autodiscover SOAP service.
 * @param < TGetSettingsResponseCollection > the generic type
 * @param < TSettingName >                   the generic type
 * @param cls                              the cls
 * @param cls1                             the cls1
 * @param identities                       Either the domains or the SMTP addresses of the users.
 * @param settings                         The settings.
 * @param requestedVersion                 Requested version of the Exchange service.
 * @param getSettingsMethod                The method to use.
 * @param getDomainMethod                  The method to calculate the domain value.
 * @return TGetSettingsResponse Collection.
 * @throws Exception the exception
 */
private <TGetSettingsResponseCollection,TSettingName>TGetSettingsResponseCollection getSettings(Class<TGetSettingsResponseCollection> cls,Class<TSettingName> cls1,List<String> identities,List<TSettingName> settings,ExchangeVersion requestedVersion,IFunctionDelegate<List<String>,List<TSettingName>,TGetSettingsResponseCollection> getSettingsMethod,IFuncDelegate<String> getDomainMethod) throws Exception {
  TGetSettingsResponseCollection response;
  if (this.getRequestedServerVersion().compareTo(MinimumRequestVersionForAutoDiscoverSoapService) < 0) {
    throw new ServiceVersionException(String.format("String_Node_Str",MinimumRequestVersionForAutoDiscoverSoapService));
  }
  if (this.url != null) {
    URI autodiscoverUrl=this.url;
    response=getSettingsMethod.func(identities,settings,requestedVersion,this.url);
    this.url=autodiscoverUrl;
    return response;
  }
 else   if (!(this.domain == null || this.domain.isEmpty())) {
    URI autodiscoverUrl=this.getAutodiscoverEndpointUrl(this.domain);
    response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
    this.url=autodiscoverUrl;
    return response;
  }
 else {
    this.isExternal=true;
    URI autodiscoverUrl;
    String domainName=getDomainMethod.func();
    int scpHostCount;
    OutParam<Integer> outParam=new OutParam<Integer>();
    List<String> hosts=this.getAutodiscoverServiceHosts(domainName,outParam);
    scpHostCount=outParam.getParam();
    if (hosts.size() == 0) {
      throw new ServiceValidationException("String_Node_Str");
    }
    for (int currentHostIndex=0; currentHostIndex < hosts.size(); currentHostIndex++) {
      String host=hosts.get(currentHostIndex);
      boolean isScpHost=currentHostIndex < scpHostCount;
      OutParam<URI> outParams=new OutParam<URI>();
      if (this.tryGetAutodiscoverEndpointUrl(host,outParams)) {
        autodiscoverUrl=outParams.getParam();
        response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
        this.url=autodiscoverUrl;
        if (isScpHost) {
          this.isExternal=false;
        }
        return response;
      }
    }
    autodiscoverUrl=this.getRedirectUrl(domainName);
    OutParam<URI> outParamUrl=new OutParam<URI>();
    if ((autodiscoverUrl != null) && this.callRedirectionUrlValidationCallback(autodiscoverUrl.toString()) && this.tryGetAutodiscoverEndpointUrl(autodiscoverUrl.getHost(),outParamUrl)) {
      autodiscoverUrl=outParamUrl.getParam();
      response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
      this.url=autodiscoverUrl;
      return response;
    }
    autodiscoverUrl=this.getRedirectionUrlFromDnsSrvRecord(domainName);
    if ((autodiscoverUrl != null) && this.callRedirectionUrlValidationCallback(autodiscoverUrl.toString()) && this.tryGetAutodiscoverEndpointUrl(autodiscoverUrl.getHost(),outParamUrl)) {
      autodiscoverUrl=outParamUrl.getParam();
      response=getSettingsMethod.func(identities,settings,requestedVersion,autodiscoverUrl);
      this.url=autodiscoverUrl;
      return response;
    }
 else {
      throw new AutodiscoverLocalException("String_Node_Str");
    }
  }
}