Program: 127
Project: 127
Buggy source:
protected final <T>void writeRequest(final Channel channel,final AsyncHttpClientConfig config,final NettyResponseFuture<T> future,final HttpRequest nettyRequest){
  try {
    if (TransferCompletionHandler.class.isAssignableFrom(future.getAsyncHandler().getClass())) {
      FluentCaseInsensitiveStringsMap h=new FluentCaseInsensitiveStringsMap();
      for (      String s : future.getNettyRequest().getHeaderNames()) {
        for (        String header : future.getNettyRequest().getHeaders(s)) {
          h.add(s,header);
        }
      }
      TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new NettyTransferAdapter(h,nettyRequest.getContent(),future.getRequest().getFile()));
    }
    if (!channel.isOpen() || !channel.isConnected()) {
      if (!remotelyClosed(channel,future)) {
        abort(future,new ConnectException());
        return;
      }
    }
    Body body=null;
    if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
      if (future.getRequest().getBodyGenerator() != null) {
        try {
          body=future.getRequest().getBodyGenerator().createBody();
        }
 catch (        IOException ex) {
          throw new IllegalStateException(ex);
        }
        long length=body.getContentLength();
        if (length != -1) {
          nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH,length);
        }
 else {
          nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING,HttpHeaders.Values.CHUNKED);
        }
      }
 else {
        body=null;
      }
    }
    if (future.getAndSetWriteHeaders(true)) {
      try {
        channel.write(nettyRequest).addListener(new ProgressListener(true,future.getAsyncHandler(),future));
      }
 catch (      Throwable cause) {
        log.debug(cause.getMessage(),cause);
        if (future.provider().remotelyClosed(channel,future)) {
          return;
        }
 else {
          future.abort(cause);
        }
      }
    }
    if (future.getAndSetWriteBody(true)) {
      if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
        if (future.getRequest().getFile() != null) {
          final File file=future.getRequest().getFile();
          long fileLength=0;
          final RandomAccessFile raf=new RandomAccessFile(file,"String_Node_Str");
          try {
            fileLength=raf.length();
            ChannelFuture writeFuture;
            if (channel.getPipeline().get(SslHandler.class) != null) {
              writeFuture=channel.write(new ChunkedFile(raf,0,fileLength,8192));
              writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future));
            }
 else {
              final FileRegion region=new OptimizedFileRegion(raf,0,fileLength);
              writeFuture=channel.write(region);
              writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future));
            }
          }
 catch (          IOException ex) {
            if (raf != null) {
              try {
                raf.close();
              }
 catch (              IOException e) {
              }
            }
            throw ex;
          }
        }
 else         if (body != null) {
          ChannelFuture writeFuture;
          if (channel.getPipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) {
            writeFuture=channel.write(new BodyFileRegion((RandomAccessBody)body));
          }
 else {
            writeFuture=channel.write(new BodyChunkedInput(body));
          }
          final Body b=body;
          writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future){
            public void operationComplete(            ChannelFuture cf){
              try {
                b.close();
              }
 catch (              IOException e) {
                log.warn("String_Node_Str",e.getMessage(),e);
              }
              super.operationComplete(cf);
            }
          }
);
        }
      }
    }
  }
 catch (  Throwable ioe) {
    if (future.provider().remotelyClosed(channel,future)) {
      return;
    }
    abort(future,ioe);
  }
  try {
    future.touch();
    int delay=requestTimeout(config,future.getRequest().getPerRequestConfig());
    if (delay != -1) {
      ReaperFuture reaperFuture=new ReaperFuture(channel,future);
      Future scheduledFuture=config.reaper().scheduleAtFixedRate(reaperFuture,delay,500,TimeUnit.MILLISECONDS);
      reaperFuture.setScheduledFuture(scheduledFuture);
      future.setReaperFuture(reaperFuture);
    }
  }
 catch (  RejectedExecutionException ex) {
    abort(future,ex);
  }
}

Fixed version (ground truth):
protected final <T>void writeRequest(final Channel channel,final AsyncHttpClientConfig config,final NettyResponseFuture<T> future,final HttpRequest nettyRequest){
  try {
    if (TransferCompletionHandler.class.isAssignableFrom(future.getAsyncHandler().getClass())) {
      FluentCaseInsensitiveStringsMap h=new FluentCaseInsensitiveStringsMap();
      for (      String s : future.getNettyRequest().getHeaderNames()) {
        for (        String header : future.getNettyRequest().getHeaders(s)) {
          h.add(s,header);
        }
      }
      TransferCompletionHandler.class.cast(future.getAsyncHandler()).transferAdapter(new NettyTransferAdapter(h,nettyRequest.getContent(),future.getRequest().getFile()));
    }
    if (!channel.isOpen() || !channel.isConnected()) {
      if (!remotelyClosed(channel,future)) {
        abort(future,new ConnectException());
        return;
      }
    }
    Body body=null;
    if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
      if (future.getRequest().getBodyGenerator() != null) {
        try {
          body=future.getRequest().getBodyGenerator().createBody();
        }
 catch (        IOException ex) {
          throw new IllegalStateException(ex);
        }
        long length=body.getContentLength();
        if (length >= 0) {
          nettyRequest.setHeader(HttpHeaders.Names.CONTENT_LENGTH,length);
        }
 else {
          nettyRequest.setHeader(HttpHeaders.Names.TRANSFER_ENCODING,HttpHeaders.Values.CHUNKED);
        }
      }
 else {
        body=null;
      }
    }
    if (future.getAndSetWriteHeaders(true)) {
      try {
        channel.write(nettyRequest).addListener(new ProgressListener(true,future.getAsyncHandler(),future));
      }
 catch (      Throwable cause) {
        log.debug(cause.getMessage(),cause);
        if (future.provider().remotelyClosed(channel,future)) {
          return;
        }
 else {
          future.abort(cause);
        }
      }
    }
    if (future.getAndSetWriteBody(true)) {
      if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
        if (future.getRequest().getFile() != null) {
          final File file=future.getRequest().getFile();
          long fileLength=0;
          final RandomAccessFile raf=new RandomAccessFile(file,"String_Node_Str");
          try {
            fileLength=raf.length();
            ChannelFuture writeFuture;
            if (channel.getPipeline().get(SslHandler.class) != null) {
              writeFuture=channel.write(new ChunkedFile(raf,0,fileLength,8192));
              writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future));
            }
 else {
              final FileRegion region=new OptimizedFileRegion(raf,0,fileLength);
              writeFuture=channel.write(region);
              writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future));
            }
          }
 catch (          IOException ex) {
            if (raf != null) {
              try {
                raf.close();
              }
 catch (              IOException e) {
              }
            }
            throw ex;
          }
        }
 else         if (body != null) {
          ChannelFuture writeFuture;
          if (channel.getPipeline().get(SslHandler.class) == null && (body instanceof RandomAccessBody)) {
            writeFuture=channel.write(new BodyFileRegion((RandomAccessBody)body));
          }
 else {
            writeFuture=channel.write(new BodyChunkedInput(body));
          }
          final Body b=body;
          writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future){
            public void operationComplete(            ChannelFuture cf){
              try {
                b.close();
              }
 catch (              IOException e) {
                log.warn("String_Node_Str",e.getMessage(),e);
              }
              super.operationComplete(cf);
            }
          }
);
        }
      }
    }
  }
 catch (  Throwable ioe) {
    if (future.provider().remotelyClosed(channel,future)) {
      return;
    }
    abort(future,ioe);
  }
  try {
    future.touch();
    int delay=requestTimeout(config,future.getRequest().getPerRequestConfig());
    if (delay != -1) {
      ReaperFuture reaperFuture=new ReaperFuture(channel,future);
      Future scheduledFuture=config.reaper().scheduleAtFixedRate(reaperFuture,delay,500,TimeUnit.MILLISECONDS);
      reaperFuture.setScheduledFuture(scheduledFuture);
      future.setReaperFuture(reaperFuture);
    }
  }
 catch (  RejectedExecutionException ex) {
    abort(future,ex);
  }
}