Program: 3947
Project: 3947
Buggy source:
/** 
 * Tries to get Autodiscover settings using redirection Url.
 * @param < TSettings >    the generic type
 * @param cls            the cls
 * @param emailAddress   The email address.
 * @param redirectionUrl Redirection Url.
 * @param settings       The settings.
 * @return boolean The boolean.
 * @throws AutodiscoverLocalException  the autodiscover local exception
 * @throws AutodiscoverRemoteException the autodiscover remote exception
 * @throws Exception                   the exception
 */
private <TSettings extends ConfigurationSettingsBase>boolean tryLastChanceHostRedirection(Class<TSettings> cls,String emailAddress,URI redirectionUrl,OutParam<TSettings> settings) throws AutodiscoverLocalException, AutodiscoverRemoteException, Exception {
  List<String> redirectionEmailAddresses=new ArrayList<String>();
  if (this.callRedirectionUrlValidationCallback(redirectionUrl.toString())) {
    for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
      try {
        settings.setParam(this.getLegacyUserSettingsAtUrl(cls,emailAddress,redirectionUrl));
switch (settings.getParam().getResponseType()) {
case Success:
          return true;
case Error:
        throw new AutodiscoverRemoteException(Strings.AutodiscoverError,settings.getParam().getError());
case RedirectAddress:
      this.disableScpLookupIfDuplicateRedirection(settings.getParam().getRedirectTarget(),redirectionEmailAddresses);
    OutParam<Integer> outParam=new OutParam<Integer>();
  outParam.setParam(currentHop);
settings.setParam(this.internalGetLegacyUserSettings(cls,emailAddress,redirectionEmailAddresses,outParam));
currentHop=outParam.getParam();
return true;
case RedirectUrl:
try {
redirectionUrl=new URI(settings.getParam().getRedirectTarget());
}
 catch (URISyntaxException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",settings.getParam().getRedirectTarget()));
return false;
}
break;
default :
String failureMessage=String.format("String_Node_Str",redirectionUrl,settings.getParam().getResponseType(),settings.getParam().getRedirectTarget());
this.traceMessage(TraceFlags.AutodiscoverConfiguration,failureMessage);
return false;
}
}
 catch (XMLStreamException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectionUrl.toString(),ex.getMessage()));
return false;
}
catch (IOException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectionUrl,ex.getMessage()));
return false;
}
catch (Exception ex) {
HttpWebRequest response=null;
OutParam<URI> outParam=new OutParam<URI>();
if ((response != null) && this.tryGetRedirectionResponse(response,outParam)) {
redirectionUrl=outParam.getParam();
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",redirectionUrl));
}
 else {
if (response != null) {
this.processHttpErrorResponse(response,ex);
}
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",url,ex.getClass().getName(),ex.getMessage()));
return false;
}
}
}
}
return false;
}

Fixed version (ground truth):
/** 
 * Tries to get Autodiscover settings using redirection Url.
 * @param < TSettings >    the generic type
 * @param cls            the cls
 * @param emailAddress   The email address.
 * @param redirectionUrl Redirection Url.
 * @param settings       The settings.
 * @return boolean The boolean.
 * @throws AutodiscoverLocalException  the autodiscover local exception
 * @throws AutodiscoverRemoteException the autodiscover remote exception
 * @throws Exception                   the exception
 */
private <TSettings extends ConfigurationSettingsBase>boolean tryLastChanceHostRedirection(Class<TSettings> cls,String emailAddress,URI redirectionUrl,OutParam<TSettings> settings) throws AutodiscoverLocalException, AutodiscoverRemoteException, Exception {
  List<String> redirectionEmailAddresses=new ArrayList<String>();
  if (this.callRedirectionUrlValidationCallback(redirectionUrl.toString())) {
    for (int currentHop=0; currentHop < AutodiscoverService.AutodiscoverMaxRedirections; currentHop++) {
      try {
        settings.setParam(this.getLegacyUserSettingsAtUrl(cls,emailAddress,redirectionUrl));
switch (settings.getParam().getResponseType()) {
case Success:
          return true;
case Error:
        throw new AutodiscoverRemoteException("String_Node_Str",settings.getParam().getError());
case RedirectAddress:
      this.disableScpLookupIfDuplicateRedirection(settings.getParam().getRedirectTarget(),redirectionEmailAddresses);
    OutParam<Integer> outParam=new OutParam<Integer>();
  outParam.setParam(currentHop);
settings.setParam(this.internalGetLegacyUserSettings(cls,emailAddress,redirectionEmailAddresses,outParam));
currentHop=outParam.getParam();
return true;
case RedirectUrl:
try {
redirectionUrl=new URI(settings.getParam().getRedirectTarget());
}
 catch (URISyntaxException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str",settings.getParam().getRedirectTarget()));
return false;
}
break;
default :
String failureMessage=String.format("String_Node_Str",redirectionUrl,settings.getParam().getResponseType(),settings.getParam().getRedirectTarget());
this.traceMessage(TraceFlags.AutodiscoverConfiguration,failureMessage);
return false;
}
}
 catch (XMLStreamException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectionUrl.toString(),ex.getMessage()));
return false;
}
catch (IOException ex) {
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",redirectionUrl,ex.getMessage()));
return false;
}
catch (Exception ex) {
HttpWebRequest response=null;
OutParam<URI> outParam=new OutParam<URI>();
if ((response != null) && this.tryGetRedirectionResponse(response,outParam)) {
redirectionUrl=outParam.getParam();
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str" + "String_Node_Str" + "String_Node_Str",redirectionUrl));
}
 else {
if (response != null) {
this.processHttpErrorResponse(response,ex);
}
this.traceMessage(TraceFlags.AutodiscoverConfiguration,String.format("String_Node_Str",url,ex.getClass().getName(),ex.getMessage()));
return false;
}
}
}
}
return false;
}