Program: 103383
Project: 103383
Buggy source:
/** 
 * Posting form to <tt>address</tt>. For submission we use POST method which is "application/x-www-form-urlencoded" encoded.
 * @param address HTTP address.
 * @param usernamePropertyName the property to use to retrieve/storeusername value if protected site is hit, for username ConfigurationService service is used.
 * @param passwordPropertyName the property to use to retrieve/storepassword value if protected site is hit, for password CredentialsStorageService service is used.
 * @param formParamNames the parameter names to include in post.
 * @param formParamValues the corresponding parameter values to use.
 * @param usernameParamIx the index of the username parameter in the<tt>formParamNames</tt> and <tt>formParamValues</tt> if any, otherwise -1.
 * @param passwordParamIx the index of the password parameter in the<tt>formParamNames</tt> and <tt>formParamValues</tt> if any, otherwise -1.
 * @return the result or null if send was not possible orcredentials ask if any was canceled.
 */
public static HTTPResponseResult postForm(String address,String usernamePropertyName,String passwordPropertyName,String[] formParamNames,String[] formParamValues,int usernameParamIx,int passwordParamIx){
  DefaultHttpClient httpClient=null;
  try {
    HttpPost postMethod=new HttpPost(address);
    httpClient=getHttpClient(usernamePropertyName,passwordPropertyName,postMethod.getURI().getHost());
    Credentials creds=null;
    if (usernameParamIx != -1 && usernameParamIx < formParamNames.length && passwordParamIx != -1 && passwordParamIx < formParamNames.length) {
      URL url=new URL(address);
      creds=new HTTPCredentialsProvider(usernamePropertyName,passwordPropertyName).getCredentials(new AuthScope(url.getHost(),url.getPort()));
    }
    List<NameValuePair> parameters=new ArrayList<NameValuePair>();
    if (formParamNames != null) {
      for (int i=0; i < formParamNames.length; i++) {
        if (i == usernameParamIx && creds != null) {
          parameters.add(new BasicNameValuePair(formParamNames[i],creds.getUserPrincipal().getName()));
        }
 else         if (i == passwordParamIx && creds != null) {
          parameters.add(new BasicNameValuePair(formParamNames[i],creds.getPassword()));
        }
 else {
          parameters.add(new BasicNameValuePair(formParamNames[i],formParamValues[i]));
        }
      }
    }
    String s=URLEncodedUtils.format(parameters,HTTP.UTF_8);
    StringEntity entity=new StringEntity(s,HTTP.UTF_8);
    entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
    postMethod.setEntity(entity);
    HttpEntity resEntity=executeMethod(httpClient,postMethod);
    if (resEntity == null)     return null;
    return new HTTPResponseResult(resEntity,httpClient);
  }
 catch (  Throwable e) {
    logger.error("String_Node_Str",e);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Posting form to <tt>address</tt>. For submission we use POST method which is "application/x-www-form-urlencoded" encoded.
 * @param httpClient the http client
 * @param postMethod the post method
 * @param address HTTP address.
 * @param usernamePropertyName the property to use to retrieve/storeusername value if protected site is hit, for username ConfigurationService service is used.
 * @param passwordPropertyName the property to use to retrieve/storepassword value if protected site is hit, for password CredentialsStorageService service is used.
 * @param formParamNames the parameter names to include in post.
 * @param formParamValues the corresponding parameter values to use.
 * @param usernameParamIx the index of the username parameter in the<tt>formParamNames</tt> and <tt>formParamValues</tt> if any, otherwise -1.
 * @param passwordParamIx the index of the password parameter in the<tt>formParamNames</tt> and <tt>formParamValues</tt> if any, otherwise -1.
 * @return the result or null if send was not possible orcredentials ask if any was canceled.
 */
private static HttpEntity postForm(DefaultHttpClient httpClient,HttpPost postMethod,String address,String usernamePropertyName,String passwordPropertyName,String[] formParamNames,String[] formParamValues,int usernameParamIx,int passwordParamIx) throws Throwable {
  Credentials creds=null;
  if (usernameParamIx != -1 && usernameParamIx < formParamNames.length && passwordParamIx != -1 && passwordParamIx < formParamNames.length) {
    URL url=new URL(address);
    HTTPCredentialsProvider prov=(HTTPCredentialsProvider)httpClient.getCredentialsProvider();
    creds=prov.getCredentials(new AuthScope(url.getHost(),url.getPort()));
    if (creds == null && !prov.retry()) {
      return null;
    }
  }
  List<NameValuePair> parameters=new ArrayList<NameValuePair>();
  if (formParamNames != null) {
    for (int i=0; i < formParamNames.length; i++) {
      if (i == usernameParamIx && creds != null) {
        parameters.add(new BasicNameValuePair(formParamNames[i],creds.getUserPrincipal().getName()));
      }
 else       if (i == passwordParamIx && creds != null) {
        parameters.add(new BasicNameValuePair(formParamNames[i],creds.getPassword()));
      }
 else {
        parameters.add(new BasicNameValuePair(formParamNames[i],formParamValues[i]));
      }
    }
  }
  String s=URLEncodedUtils.format(parameters,HTTP.UTF_8);
  StringEntity entity=new StringEntity(s,HTTP.UTF_8);
  entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
  postMethod.setEntity(entity);
  return executeMethod(httpClient,postMethod);
}