Program: 162
Project: 162
Buggy source:
private <T>Future<T> doConnect(final Request request,final AsyncHandler<T> asyncHandler,NettyResponseFuture<T> f) throws IOException {
  if (isClose.get()) {
    throw new IOException("String_Node_Str");
  }
  if (config.getMaxTotalConnections() != -1 && activeConnectionsCount.getAndIncrement() >= config.getMaxTotalConnections()) {
    activeConnectionsCount.decrementAndGet();
    throw new IOException("String_Node_Str");
  }
  URI uri=createUri(request.getUrl());
  log.debug("String_Node_Str",uri);
  Channel channel=lookupInCache(uri);
  if (channel != null && channel.isOpen()) {
    if (channel.isConnected()) {
      if (config.getMaxConnectionPerHost() != -1) {
        activeConnectionsCount.decrementAndGet();
      }
      HttpRequest nettyRequest=buildRequest(config,request,uri,false);
      if (f == null) {
        f=new NettyResponseFuture<T>(uri,request,asyncHandler,nettyRequest,config.getRequestTimeoutInMs());
      }
 else {
        f.setNettyRequest(nettyRequest);
      }
      try {
        executeRequest(channel,config,f,nettyRequest);
        return f;
      }
 catch (      ConnectException ex) {
        connectionsPool.remove(channel);
      }
    }
 else {
      connectionsPool.remove(channel);
    }
  }
  ConnectListener<T> c=new ConnectListener.Builder<T>(config,request,asyncHandler,f).build();
  boolean useSSl=uri.getScheme().compareToIgnoreCase("String_Node_Str") == 0 && (request.getProxyServer() == null || !request.getProxyServer().getProtocolAsString().equals("String_Node_Str"));
  configure(useSSl,c);
  ChannelFuture channelFuture;
  try {
    if (config.getProxyServer() == null && request.getProxyServer() == null) {
      channelFuture=bootstrap.connect(new InetSocketAddress(uri.getHost(),getPort(uri)));
    }
 else {
      ProxyServer proxy=(request.getProxyServer() == null ? config.getProxyServer() : request.getProxyServer());
      channelFuture=bootstrap.connect(new InetSocketAddress(proxy.getHost(),proxy.getPort()));
    }
    bootstrap.setOption("String_Node_Str",config.getConnectionTimeoutInMs());
  }
 catch (  Throwable t) {
    if (config.getMaxTotalConnections() != -1) {
      activeConnectionsCount.decrementAndGet();
    }
    log.error(t);
    c.future().abort(t.getCause());
    return c.future();
  }
  channelFuture.addListener(c);
  openChannels.add(channelFuture.getChannel());
  return c.future();
}

Fixed version (ground truth):
private <T>Future<T> doConnect(final Request request,final AsyncHandler<T> asyncHandler,NettyResponseFuture<T> f) throws IOException {
  if (isClose.get()) {
    throw new IOException("String_Node_Str");
  }
  if (config.getMaxTotalConnections() != -1 && activeConnectionsCount.getAndIncrement() >= config.getMaxTotalConnections()) {
    activeConnectionsCount.decrementAndGet();
    throw new IOException("String_Node_Str");
  }
  URI uri=createUri(request.getUrl());
  log.debug("String_Node_Str",uri);
  Channel channel=lookupInCache(uri);
  if (channel != null && channel.isOpen()) {
    if (channel.isConnected()) {
      if (config.getMaxConnectionPerHost() != -1) {
        activeConnectionsCount.decrementAndGet();
      }
      HttpRequest nettyRequest=buildRequest(config,request,uri,false);
      if (f == null) {
        f=new NettyResponseFuture<T>(uri,request,asyncHandler,nettyRequest,requestTimeout(config,request.getPerRequestConfig()));
      }
 else {
        f.setNettyRequest(nettyRequest);
      }
      try {
        executeRequest(channel,config,f,nettyRequest);
        return f;
      }
 catch (      ConnectException ex) {
        connectionsPool.remove(channel);
      }
    }
 else {
      connectionsPool.remove(channel);
    }
  }
  ConnectListener<T> c=new ConnectListener.Builder<T>(config,request,asyncHandler,f).build();
  boolean useSSl=uri.getScheme().compareToIgnoreCase("String_Node_Str") == 0 && (request.getProxyServer() == null || !request.getProxyServer().getProtocolAsString().equals("String_Node_Str"));
  configure(useSSl,c);
  ChannelFuture channelFuture;
  try {
    if (config.getProxyServer() == null && request.getProxyServer() == null) {
      channelFuture=bootstrap.connect(new InetSocketAddress(uri.getHost(),getPort(uri)));
    }
 else {
      ProxyServer proxy=(request.getProxyServer() == null ? config.getProxyServer() : request.getProxyServer());
      channelFuture=bootstrap.connect(new InetSocketAddress(proxy.getHost(),proxy.getPort()));
    }
    bootstrap.setOption("String_Node_Str",config.getConnectionTimeoutInMs());
  }
 catch (  Throwable t) {
    if (config.getMaxTotalConnections() != -1) {
      activeConnectionsCount.decrementAndGet();
    }
    log.error(t);
    c.future().abort(t.getCause());
    return c.future();
  }
  channelFuture.addListener(c);
  openChannels.add(channelFuture.getChannel());
  return c.future();
}