Program: 120
Project: 120
Buggy source:
private void configure(URI uri,HttpURLConnection urlConnection,Request request) throws IOException, AuthenticationException {
  PerRequestConfig conf=request.getPerRequestConfig();
  int requestTimeout=(conf != null && conf.getRequestTimeoutInMs() != 0) ? conf.getRequestTimeoutInMs() : config.getRequestTimeoutInMs();
  urlConnection.setConnectTimeout(config.getConnectionTimeoutInMs());
  if (requestTimeout != -1)   urlConnection.setReadTimeout(requestTimeout);
  urlConnection.setInstanceFollowRedirects(false);
  String host=uri.getHost();
  String method=request.getMethod();
  if (request.getVirtualHost() != null) {
    host=request.getVirtualHost();
  }
  if (uri.getPort() == -1) {
    urlConnection.setRequestProperty("String_Node_Str",host);
  }
 else {
    urlConnection.setRequestProperty("String_Node_Str",host + "String_Node_Str" + uri.getPort());
  }
  if (config.isCompressionEnabled()) {
    urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
  }
  boolean contentTypeSet=false;
  if (!method.equalsIgnoreCase("String_Node_Str")) {
    FluentCaseInsensitiveStringsMap h=request.getHeaders();
    if (h != null) {
      for (      String name : h.keySet()) {
        if (!"String_Node_Str".equalsIgnoreCase(name)) {
          for (          String value : h.get(name)) {
            urlConnection.setRequestProperty(name,value);
            if (name.equalsIgnoreCase("String_Node_Str")) {
              throw new IllegalStateException("String_Node_Str");
            }
          }
        }
      }
    }
  }
  String ka=config.getAllowPoolingConnection() ? "String_Node_Str" : "String_Node_Str";
  urlConnection.setRequestProperty("String_Node_Str",ka);
  ProxyServer proxyServer=request.getProxyServer() != null ? request.getProxyServer() : config.getProxyServer();
  if (proxyServer != null) {
    urlConnection.setRequestProperty("String_Node_Str",ka);
    if (proxyServer.getPrincipal() != null) {
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeBasicAuthentication(proxyServer));
    }
  }
  Realm realm=request.getRealm() != null ? request.getRealm() : config.getRealm();
  if (realm != null && realm.getUsePreemptiveAuth()) {
switch (realm.getAuthScheme()) {
case BASIC:
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeBasicAuthentication(realm));
    break;
case DIGEST:
  if (realm.getNonce() != null && !realm.getNonce().equals("String_Node_Str")) {
    try {
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeDigestAuthentication(realm));
    }
 catch (    NoSuchAlgorithmException e) {
      throw new SecurityException(e);
    }
  }
break;
case NTLM:
jdkNtlmDomain=System.getProperty(NTLM_DOMAIN);
System.setProperty(NTLM_DOMAIN,realm.getDomain());
break;
default :
throw new IllegalStateException(String.format("String_Node_Str",realm.toString()));
}
}
if (request.getHeaders().getFirstValue("String_Node_Str") == null) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
}
if (request.getHeaders().getFirstValue("String_Node_Str") == null && config.getUserAgent() != null) {
urlConnection.setRequestProperty("String_Node_Str",config.getUserAgent());
}
 else {
urlConnection.setRequestProperty("String_Node_Str",AsyncHttpProviderUtils.constructUserAgent(JDKAsyncHttpProvider.class));
}
if (request.getCookies() != null && !request.getCookies().isEmpty()) {
urlConnection.setRequestProperty("String_Node_Str",AsyncHttpProviderUtils.encodeCookies(request.getCookies()));
}
String reqType=request.getMethod();
urlConnection.setRequestMethod(reqType);
if ("String_Node_Str".equals(reqType) || "String_Node_Str".equals(reqType)) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
urlConnection.setDoOutput(true);
if (cachedBytes != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(cachedBytesLenght));
urlConnection.setFixedLengthStreamingMode(cachedBytesLenght);
urlConnection.getOutputStream().write(cachedBytes,0,cachedBytesLenght);
}
 else if (request.getByteData() != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(request.getByteData().length));
urlConnection.setFixedLengthStreamingMode(request.getByteData().length);
urlConnection.getOutputStream().write(request.getByteData());
}
 else if (request.getStringData() != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(request.getStringData().length()));
urlConnection.getOutputStream().write(request.getStringData().getBytes("String_Node_Str"));
}
 else if (request.getStreamData() != null) {
int[] lengthWrapper=new int[1];
cachedBytes=AsyncHttpProviderUtils.readFully(request.getStreamData(),lengthWrapper);
cachedBytesLenght=lengthWrapper[0];
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(cachedBytesLenght));
urlConnection.setFixedLengthStreamingMode(cachedBytesLenght);
urlConnection.getOutputStream().write(cachedBytes,0,cachedBytesLenght);
}
 else if (request.getParams() != null) {
StringBuilder sb=new StringBuilder();
for (final Map.Entry<String,List<String>> paramEntry : request.getParams()) {
final String key=paramEntry.getKey();
for (final String value : paramEntry.getValue()) {
if (sb.length() > 0) {
sb.append("String_Node_Str");
}
UTF8UrlEncoder.appendEncoded(sb,key);
sb.append("String_Node_Str");
UTF8UrlEncoder.appendEncoded(sb,value);
}
}
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(sb.length()));
urlConnection.setFixedLengthStreamingMode(sb.length());
if (!request.getHeaders().containsKey("String_Node_Str")) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
}
urlConnection.getOutputStream().write(sb.toString().getBytes("String_Node_Str"));
}
 else if (request.getParts() != null) {
int lenght=(int)request.getLength();
if (lenght != -1) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(lenght));
urlConnection.setFixedLengthStreamingMode(lenght);
}
if (lenght == -1) {
lenght=MAX_BUFFERED_BYTES;
}
MultipartRequestEntity mre=AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(),request.getParams());
urlConnection.setRequestProperty("String_Node_Str",mre.getContentType());
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(mre.getContentLength()));
ChannelBuffer b=ChannelBuffers.dynamicBuffer(lenght);
mre.writeRequest(urlConnection.getOutputStream());
}
 else if (request.getEntityWriter() != null) {
int lenght=(int)request.getLength();
if (lenght != -1) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(lenght));
urlConnection.setFixedLengthStreamingMode(lenght);
}
request.getEntityWriter().writeEntity(urlConnection.getOutputStream());
}
 else if (request.getFile() != null) {
File file=request.getFile();
if (!file.isFile()) {
throw new IOException(String.format(Thread.currentThread() + "String_Node_Str",file.getAbsolutePath()));
}
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(file.length()));
urlConnection.setFixedLengthStreamingMode((int)file.length());
FileInputStream fis=new FileInputStream(file);
try {
OutputStream os=urlConnection.getOutputStream();
for (final byte[] buffer=new byte[1024 * 16]; ; ) {
int read=fis.read(buffer);
if (read < 0) {
break;
}
os.write(buffer,0,read);
}
}
  finally {
fis.close();
}
}
 else if (request.getBodyGenerator() != null) {
Body body=request.getBodyGenerator().createBody();
try {
int length=(int)body.getContentLength();
if (length < 0) {
length=(int)request.getLength();
}
if (length >= 0) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(length));
urlConnection.setFixedLengthStreamingMode(length);
}
OutputStream os=urlConnection.getOutputStream();
for (ByteBuffer buffer=ByteBuffer.allocate(1024 * 8); ; ) {
buffer.clear();
if (body.read(buffer) < 0) {
break;
}
os.write(buffer.array(),buffer.arrayOffset(),buffer.position());
}
}
  finally {
try {
body.close();
}
 catch (IOException e) {
logger.warn("String_Node_Str",e.getMessage(),e);
}
}
}
}
}

Fixed version (ground truth):
private void configure(URI uri,HttpURLConnection urlConnection,Request request) throws IOException, AuthenticationException {
  PerRequestConfig conf=request.getPerRequestConfig();
  int requestTimeout=(conf != null && conf.getRequestTimeoutInMs() != 0) ? conf.getRequestTimeoutInMs() : config.getRequestTimeoutInMs();
  urlConnection.setConnectTimeout(config.getConnectionTimeoutInMs());
  if (requestTimeout != -1)   urlConnection.setReadTimeout(requestTimeout);
  urlConnection.setInstanceFollowRedirects(false);
  String host=uri.getHost();
  String method=request.getMethod();
  if (request.getVirtualHost() != null) {
    host=request.getVirtualHost();
  }
  if (uri.getPort() == -1) {
    urlConnection.setRequestProperty("String_Node_Str",host);
  }
 else {
    urlConnection.setRequestProperty("String_Node_Str",host + "String_Node_Str" + uri.getPort());
  }
  if (config.isCompressionEnabled()) {
    urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
  }
  boolean contentTypeSet=false;
  if (!method.equalsIgnoreCase("String_Node_Str")) {
    FluentCaseInsensitiveStringsMap h=request.getHeaders();
    if (h != null) {
      for (      String name : h.keySet()) {
        if (!"String_Node_Str".equalsIgnoreCase(name)) {
          for (          String value : h.get(name)) {
            urlConnection.setRequestProperty(name,value);
            if (name.equalsIgnoreCase("String_Node_Str")) {
              throw new IllegalStateException("String_Node_Str");
            }
          }
        }
      }
    }
  }
  String ka=config.getAllowPoolingConnection() ? "String_Node_Str" : "String_Node_Str";
  urlConnection.setRequestProperty("String_Node_Str",ka);
  ProxyServer proxyServer=request.getProxyServer() != null ? request.getProxyServer() : config.getProxyServer();
  if (proxyServer != null) {
    urlConnection.setRequestProperty("String_Node_Str",ka);
    if (proxyServer.getPrincipal() != null) {
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeBasicAuthentication(proxyServer));
    }
  }
  Realm realm=request.getRealm() != null ? request.getRealm() : config.getRealm();
  if (realm != null && realm.getUsePreemptiveAuth()) {
switch (realm.getAuthScheme()) {
case BASIC:
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeBasicAuthentication(realm));
    break;
case DIGEST:
  if (realm.getNonce() != null && !realm.getNonce().equals("String_Node_Str")) {
    try {
      urlConnection.setRequestProperty("String_Node_Str",AuthenticatorUtils.computeDigestAuthentication(realm));
    }
 catch (    NoSuchAlgorithmException e) {
      throw new SecurityException(e);
    }
  }
break;
case NTLM:
jdkNtlmDomain=System.getProperty(NTLM_DOMAIN);
System.setProperty(NTLM_DOMAIN,realm.getDomain());
break;
default :
throw new IllegalStateException(String.format("String_Node_Str",realm.toString()));
}
}
if (request.getHeaders().getFirstValue("String_Node_Str") == null) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
}
if (request.getHeaders().getFirstValue("String_Node_Str") == null && config.getUserAgent() != null) {
urlConnection.setRequestProperty("String_Node_Str",config.getUserAgent());
}
 else {
urlConnection.setRequestProperty("String_Node_Str",AsyncHttpProviderUtils.constructUserAgent(JDKAsyncHttpProvider.class));
}
if (request.getCookies() != null && !request.getCookies().isEmpty()) {
urlConnection.setRequestProperty("String_Node_Str",AsyncHttpProviderUtils.encodeCookies(request.getCookies()));
}
String reqType=request.getMethod();
urlConnection.setRequestMethod(reqType);
if ("String_Node_Str".equals(reqType) || "String_Node_Str".equals(reqType)) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
urlConnection.setDoOutput(true);
if (cachedBytes != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(cachedBytesLenght));
urlConnection.setFixedLengthStreamingMode(cachedBytesLenght);
urlConnection.getOutputStream().write(cachedBytes,0,cachedBytesLenght);
}
 else if (request.getByteData() != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(request.getByteData().length));
urlConnection.setFixedLengthStreamingMode(request.getByteData().length);
urlConnection.getOutputStream().write(request.getByteData());
}
 else if (request.getStringData() != null) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(request.getStringData().length()));
byte[] b=request.getStringData().getBytes("String_Node_Str");
urlConnection.setFixedLengthStreamingMode(b.length);
urlConnection.getOutputStream().write(b);
}
 else if (request.getStreamData() != null) {
int[] lengthWrapper=new int[1];
cachedBytes=AsyncHttpProviderUtils.readFully(request.getStreamData(),lengthWrapper);
cachedBytesLenght=lengthWrapper[0];
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(cachedBytesLenght));
urlConnection.setFixedLengthStreamingMode(cachedBytesLenght);
urlConnection.getOutputStream().write(cachedBytes,0,cachedBytesLenght);
}
 else if (request.getParams() != null) {
StringBuilder sb=new StringBuilder();
for (final Map.Entry<String,List<String>> paramEntry : request.getParams()) {
final String key=paramEntry.getKey();
for (final String value : paramEntry.getValue()) {
if (sb.length() > 0) {
sb.append("String_Node_Str");
}
UTF8UrlEncoder.appendEncoded(sb,key);
sb.append("String_Node_Str");
UTF8UrlEncoder.appendEncoded(sb,value);
}
}
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(sb.length()));
urlConnection.setFixedLengthStreamingMode(sb.length());
if (!request.getHeaders().containsKey("String_Node_Str")) {
urlConnection.setRequestProperty("String_Node_Str","String_Node_Str");
}
urlConnection.getOutputStream().write(sb.toString().getBytes("String_Node_Str"));
}
 else if (request.getParts() != null) {
int lenght=(int)request.getLength();
if (lenght != -1) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(lenght));
urlConnection.setFixedLengthStreamingMode(lenght);
}
if (lenght == -1) {
lenght=MAX_BUFFERED_BYTES;
}
MultipartRequestEntity mre=AsyncHttpProviderUtils.createMultipartRequestEntity(request.getParts(),request.getParams());
urlConnection.setRequestProperty("String_Node_Str",mre.getContentType());
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(mre.getContentLength()));
ChannelBuffer b=ChannelBuffers.dynamicBuffer(lenght);
mre.writeRequest(urlConnection.getOutputStream());
}
 else if (request.getEntityWriter() != null) {
int lenght=(int)request.getLength();
if (lenght != -1) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(lenght));
urlConnection.setFixedLengthStreamingMode(lenght);
}
request.getEntityWriter().writeEntity(urlConnection.getOutputStream());
}
 else if (request.getFile() != null) {
File file=request.getFile();
if (!file.isFile()) {
throw new IOException(String.format(Thread.currentThread() + "String_Node_Str",file.getAbsolutePath()));
}
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(file.length()));
urlConnection.setFixedLengthStreamingMode((int)file.length());
FileInputStream fis=new FileInputStream(file);
try {
OutputStream os=urlConnection.getOutputStream();
for (final byte[] buffer=new byte[1024 * 16]; ; ) {
int read=fis.read(buffer);
if (read < 0) {
break;
}
os.write(buffer,0,read);
}
}
  finally {
fis.close();
}
}
 else if (request.getBodyGenerator() != null) {
Body body=request.getBodyGenerator().createBody();
try {
int length=(int)body.getContentLength();
if (length < 0) {
length=(int)request.getLength();
}
if (length >= 0) {
urlConnection.setRequestProperty("String_Node_Str",String.valueOf(length));
urlConnection.setFixedLengthStreamingMode(length);
}
OutputStream os=urlConnection.getOutputStream();
for (ByteBuffer buffer=ByteBuffer.allocate(1024 * 8); ; ) {
buffer.clear();
if (body.read(buffer) < 0) {
break;
}
os.write(buffer.array(),buffer.arrayOffset(),buffer.position());
}
}
  finally {
try {
body.close();
}
 catch (IOException e) {
logger.warn("String_Node_Str",e.getMessage(),e);
}
}
}
}
}