Program: 34266
Project: 34266
Buggy source:
private boolean postBatchEvents(List<ByteArrayEntity> batch){
  final long NANOS_PER_SECOND=1000L * 1000L * 1000L;
  final long NANOS_PER_MILLI_SECOND=1000L * 1000L;
  int pickedUrlIdx;
  try (Timer.Context ctx=postTime.time()){
    long timeBeforePost=System.nanoTime();
    postCount.inc();
    if (roundRobin) {
      pickedUrlIdx=currentUrl;
    }
 else {
      pickedUrlIdx=leastResponseIdx(responseTime);
    }
    HttpPost post=new HttpPost(urls.get(pickedUrlIdx));
    if (roundRobin) {
      currentUrl=(currentUrl + 1) % urls.size();
    }
    post.setHeader("String_Node_Str","String_Node_Str");
    if (batchSize == 1 && batch.size() == 1) {
      post.setEntity(batch.get(0));
      batch.clear();
    }
 else {
      try {
        ByteArrayEntity packedEntities=ListSerializer.toByteArrayEntity(batch);
        post.setEntity(packedEntities);
        batch.clear();
      }
 catch (      InvalidMessageSizeException ex) {
        postFailure.inc();
        batch.clear();
        return false;
      }
    }
    CloseableHttpResponse response=client.execute(post);
    int statusCode=response.getStatusLine().getStatusCode();
    long timeAfterPost=System.nanoTime();
    if (statusCode >= 200 && statusCode < 300) {
      postSuccess.inc();
    }
 else {
      postFailure.inc();
    }
    responseTimestamp[pickedUrlIdx]=timeAfterPost;
    responseTime[pickedUrlIdx]=(timeAfterPost - timeBeforePost) + 2 * NANOS_PER_MILLI_SECOND;
    for (int i=0; i < responseTimestamp.length; ++i) {
      if ((timeAfterPost - responseTimestamp[i]) > responseDecayingHalflife * NANOS_PER_SECOND) {
        responseTimestamp[i]=timeAfterPost;
        responseTime[i]=responseTime[i] / 2;
      }
    }
    long currentTime=new Date().getTime();
    if (currentTime - lastReconnect > 10000) {
      lastReconnect=currentTime;
      response.close();
    }
 else {
      EntityUtils.consume(response.getEntity());
    }
  }
 catch (  IOException e) {
    System.out.println("String_Node_Str");
    e.printStackTrace();
    postFailure.inc();
    return false;
  }
  return true;
}

Fixed version (ground truth):
private boolean postBatchEvents(List<ByteArrayEntity> batch){
  final long NANOS_PER_SECOND=1000L * 1000L * 1000L;
  final long NANOS_PER_MILLI_SECOND=1000L * 1000L;
  int pickedUrlIdx;
  try (Timer.Context ctx=postTime.time()){
    long timeBeforePost=System.nanoTime();
    postCount.inc();
    if (roundRobin) {
      pickedUrlIdx=currentUrl;
    }
 else {
      pickedUrlIdx=leastResponseIdx(responseTime);
    }
    HttpPost post=new HttpPost(urls.get(pickedUrlIdx));
    if (roundRobin) {
      currentUrl=(currentUrl + 1) % urls.size();
    }
    post.setHeader("String_Node_Str","String_Node_Str");
    responseTimestamp[pickedUrlIdx]=System.nanoTime();
    responseTime[pickedUrlIdx]=5 * NANOS_PER_SECOND;
    if (batchSize == 1 && batch.size() == 1) {
      post.setEntity(batch.get(0));
      batch.clear();
    }
 else {
      try {
        ByteArrayEntity packedEntities=ListSerializer.toByteArrayEntity(batch);
        post.setEntity(packedEntities);
        batch.clear();
      }
 catch (      InvalidMessageSizeException ex) {
        postFailure.inc();
        batch.clear();
        return false;
      }
    }
    CloseableHttpResponse response=client.execute(post);
    int statusCode=response.getStatusLine().getStatusCode();
    long timeAfterPost=System.nanoTime();
    if (statusCode >= 200 && statusCode < 300) {
      postSuccess.inc();
      responseTimestamp[pickedUrlIdx]=timeAfterPost;
      responseTime[pickedUrlIdx]=(timeAfterPost - timeBeforePost) + 2 * NANOS_PER_MILLI_SECOND;
    }
 else {
      postFailure.inc();
      responseTimestamp[pickedUrlIdx]=timeAfterPost;
      responseTime[pickedUrlIdx]=(timeAfterPost - timeBeforePost) + 5 * NANOS_PER_SECOND;
    }
    for (int i=0; i < responseTimestamp.length; ++i) {
      if ((timeAfterPost - responseTimestamp[i]) > responseDecayingHalflife * NANOS_PER_SECOND) {
        responseTimestamp[i]=timeAfterPost;
        responseTime[i]=responseTime[i] / 2;
      }
    }
    long currentTime=new Date().getTime();
    if (currentTime - lastReconnect > 10000) {
      lastReconnect=currentTime;
      response.close();
    }
 else {
      EntityUtils.consume(response.getEntity());
    }
  }
 catch (  IOException e) {
    System.out.println("String_Node_Str");
    e.printStackTrace();
    postFailure.inc();
    return false;
  }
  return true;
}