Program: 103382
Project: 103382
Buggy source:
/** 
 * Executes the metod and return the result. Handle ask for password when hitting password protected site. Keep asking for password till user clicks cancel or enters correct password. When 'remember password' is checked password is saved, if this password and username are not correct clear them, if there are correct they stay saved.
 * @param httpClient the configured http client to use.
 * @param req the request for now it is get or post.
 * @return the result http entity.
 */
private static HttpEntity executeMethod(DefaultHttpClient httpClient,HttpRequestBase req) throws Throwable {
  HttpResponse response=null;
  int redirects=0;
  while (response == null || response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
    if (response != null) {
      if (logger.isDebugEnabled())       logger.debug("String_Node_Str" + "String_Node_Str");
      URI uri=req.getURI();
      req.abort();
      req=req.getClass().newInstance();
      req.setURI(uri);
      httpClient.getCredentialsProvider().clear();
      response=httpClient.execute(req);
    }
 else     response=httpClient.execute(req);
    if (!((HTTPCredentialsProvider)httpClient.getCredentialsProvider()).retry()) {
      if (logger.isDebugEnabled())       logger.debug("String_Node_Str");
      break;
    }
    Header locationHeader=response.getFirstHeader("String_Node_Str");
    if (locationHeader != null && req instanceof HttpPost && (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY || response.getStatusLine().getStatusCode() == HttpStatus.SC_SEE_OTHER) && redirects < MAX_REDIRECTS) {
      HttpRequestBase oldreq=req;
      oldreq.abort();
      String newLocation=locationHeader.getValue();
      HttpEntity en=((HttpPost)oldreq).getEntity();
      if (en != null && en instanceof StringEntity) {
        ByteArrayOutputStream out=new ByteArrayOutputStream();
        en.writeTo(out);
        newLocation+="String_Node_Str" + out.toString("String_Node_Str");
      }
      req=new HttpGet(newLocation);
      req.setParams(oldreq.getParams());
      req.setHeaders(oldreq.getAllHeaders());
      redirects++;
      response=httpClient.execute(req);
    }
  }
  if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    return response.getEntity();
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Executes the method and return the result. Handle ask for password when hitting password protected site. Keep asking for password till user clicks cancel or enters correct password. When 'remember password' is checked password is saved, if this password and username are not correct clear them, if there are correct they stay saved.
 * @param httpClient the configured http client to use.
 * @param req the request for now it is get or post.
 * @return the result http entity.
 */
private static HttpEntity executeMethod(DefaultHttpClient httpClient,HttpRequestBase req) throws Throwable {
  HttpResponse response=null;
  int redirects=0;
  while (response == null || response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
    if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
      if (logger.isDebugEnabled())       logger.debug("String_Node_Str" + "String_Node_Str");
      URI uri=req.getURI();
      req.abort();
      req=req.getClass().newInstance();
      req.setURI(uri);
      httpClient.getCredentialsProvider().clear();
      if (!((HTTPCredentialsProvider)httpClient.getCredentialsProvider()).isChallengedForCredentials()) {
        throw new AuthenticationException("String_Node_Str");
      }
 else {
        response=httpClient.execute(req);
      }
    }
 else     response=httpClient.execute(req);
    if (!((HTTPCredentialsProvider)httpClient.getCredentialsProvider()).retry()) {
      if (logger.isDebugEnabled())       logger.debug("String_Node_Str");
      break;
    }
    Header locationHeader=response.getFirstHeader("String_Node_Str");
    if (locationHeader != null && req instanceof HttpPost && (response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || response.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY || response.getStatusLine().getStatusCode() == HttpStatus.SC_SEE_OTHER) && redirects < MAX_REDIRECTS) {
      HttpRequestBase oldreq=req;
      oldreq.abort();
      String newLocation=locationHeader.getValue();
      HttpEntity en=((HttpPost)oldreq).getEntity();
      if (en != null && en instanceof StringEntity) {
        ByteArrayOutputStream out=new ByteArrayOutputStream();
        en.writeTo(out);
        newLocation+="String_Node_Str" + out.toString("String_Node_Str");
      }
      req=new HttpGet(newLocation);
      req.setParams(oldreq.getParams());
      req.setHeaders(oldreq.getAllHeaders());
      redirects++;
      response=httpClient.execute(req);
    }
  }
  if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    return response.getEntity();
  }
  return null;
}