Program: 138
Project: 138
Buggy source:
protected final <T>void writeRequest(final Channel channel,final AsyncHttpClientConfig config,final NettyResponseFuture<T> future,final HttpRequest nettyRequest){
  try {
    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 {
        body=null;
      }
    }
    channel.write(nettyRequest).addListener(new ProgressListener(true,future.getAsyncHandler(),future));
    if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
      RandomAccessFile raf=null;
      if (future.getRequest().getFile() != null) {
        final File file=future.getRequest().getFile();
        long fileLength=0;
        try {
          raf=new RandomAccessFile(file,"String_Node_Str");
          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 DefaultFileRegion(raf.getChannel(),0,fileLength);
            writeFuture=channel.write(region);
            writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future){
              public void operationComplete(              ChannelFuture cf){
                region.releaseExternalResources();
                super.operationComplete(cf);
              }
            }
);
          }
        }
  finally {
          if (raf != null)           try {
            raf.close();
          }
 catch (          IOException e) {
          }
        }
      }
 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(e,"String_Node_Str",e.getMessage());
            }
            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,delay,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 (!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 {
        body=null;
      }
    }
    try {
      channel.write(nettyRequest).addListener(new ProgressListener(true,future.getAsyncHandler(),future));
    }
 catch (    Throwable cause) {
      if (log.isDebugEnabled()) {
        log.debug(cause);
      }
      if (future.provider().remotelyClosed(channel,future)) {
        return;
      }
 else {
        future.abort(cause);
      }
    }
    if (!future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT)) {
      RandomAccessFile raf=null;
      if (future.getRequest().getFile() != null) {
        final File file=future.getRequest().getFile();
        long fileLength=0;
        try {
          raf=new RandomAccessFile(file,"String_Node_Str");
          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 DefaultFileRegion(raf.getChannel(),0,fileLength);
            writeFuture=channel.write(region);
            writeFuture.addListener(new ProgressListener(false,future.getAsyncHandler(),future){
              public void operationComplete(              ChannelFuture cf){
                region.releaseExternalResources();
                super.operationComplete(cf);
              }
            }
);
          }
        }
  finally {
          if (raf != null)           try {
            raf.close();
          }
 catch (          IOException e) {
          }
        }
      }
 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(e,"String_Node_Str",e.getMessage());
            }
            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,delay,TimeUnit.MILLISECONDS);
      reaperFuture.setScheduledFuture(scheduledFuture);
      future.setReaperFuture(reaperFuture);
    }
  }
 catch (  RejectedExecutionException ex) {
    abort(future,ex);
  }
}