Program: 3918
Project: 3918
Buggy source:
/** 
 * Gets the enabled autodiscover endpoints on a specific host.
 * @param host      The host.
 * @param endpoints Endpoints found for host.
 * @return Flags indicating which endpoints are enabled.
 * @throws Exception the exception
 */
private boolean tryGetEnabledEndpointsForHost(String host,OutParam<EnumSet<AutodiscoverEndpoints>> endpoints) throws Exception {
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",host));
  for (int currentHop=0; currentHop < AutodiscoverMaxRedirections; currentHop++) {
    URI autoDiscoverUrl=new URI(String.format(AutodiscoverLegacyHttpsUrl,host));
    endpoints.setParam(EnumSet.of(AutodiscoverEndpoints.None));
    HttpWebRequest request=null;
    try {
      request=new HttpClientWebRequest(httpClient,httpContext);
      try {
        request.setUrl(autoDiscoverUrl.toURL());
      }
 catch (      MalformedURLException e) {
        String strErr=String.format("String_Node_Str",url);
        throw new ServiceLocalException(strErr);
      }
      request.setRequestMethod("String_Node_Str");
      request.setAllowAutoRedirect(false);
      request.setPreAuthenticate(false);
      request.setUseDefaultCredentials(this.getUseDefaultCredentials());
      prepareCredentials(request);
      request.prepareConnection();
      try {
        request.executeRequest();
      }
 catch (      IOException e) {
        return false;
      }
      OutParam<URI> outParam=new OutParam<URI>();
      if (this.tryGetRedirectionResponse(request,outParam)) {
        URI redirectUrl=outParam.getParam();
        this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectUrl.getHost()));
        host=redirectUrl.getHost();
      }
 else {
        endpoints.setParam(this.getEndpointsFromHttpWebResponse(request));
        this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",endpoints.getParam().toString()));
        return true;
      }
    }
  finally {
      if (request != null) {
        try {
          request.close();
        }
 catch (        Exception e) {
        }
      }
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new MaximumRedirectionHopsExceededException();
}

Fixed version (ground truth):
/** 
 * Gets the enabled autodiscover endpoints on a specific host.
 * @param host      The host.
 * @param endpoints Endpoints found for host.
 * @return Flags indicating which endpoints are enabled.
 * @throws Exception the exception
 */
private boolean tryGetEnabledEndpointsForHost(String host,OutParam<EnumSet<AutodiscoverEndpoints>> endpoints) throws Exception {
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",host));
  for (int currentHop=0; currentHop < AutodiscoverMaxRedirections; currentHop++) {
    URI autoDiscoverUrl=new URI(String.format(AutodiscoverLegacyHttpsUrl,host));
    endpoints.setParam(EnumSet.of(AutodiscoverEndpoints.None));
    HttpWebRequest request=null;
    try {
      request=new HttpClientWebRequest(httpClient,httpContext);
      request.setProxy(getWebProxy());
      try {
        request.setUrl(autoDiscoverUrl.toURL());
      }
 catch (      MalformedURLException e) {
        String strErr=String.format("String_Node_Str",url);
        throw new ServiceLocalException(strErr);
      }
      request.setRequestMethod("String_Node_Str");
      request.setAllowAutoRedirect(false);
      request.setPreAuthenticate(false);
      request.setUseDefaultCredentials(this.getUseDefaultCredentials());
      prepareCredentials(request);
      request.prepareConnection();
      try {
        request.executeRequest();
      }
 catch (      IOException e) {
        return false;
      }
      OutParam<URI> outParam=new OutParam<URI>();
      if (this.tryGetRedirectionResponse(request,outParam)) {
        URI redirectUrl=outParam.getParam();
        this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectUrl.getHost()));
        host=redirectUrl.getHost();
      }
 else {
        endpoints.setParam(this.getEndpointsFromHttpWebResponse(request));
        this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",endpoints.getParam().toString()));
        return true;
      }
    }
  finally {
      if (request != null) {
        try {
          request.close();
        }
 catch (        Exception e) {
        }
      }
    }
  }
  this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",AutodiscoverMaxRedirections));
  throw new MaximumRedirectionHopsExceededException();
}