Program: 142
Project: 142
Buggy source:
@Override public void messageReceived(final ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  super.messageReceived(ctx,e);
  IN_IO_THREAD.set(Boolean.TRUE);
  if (log.isDebugEnabled()) {
    log.debug(String.format(currentThread() + "String_Node_Str",e.getClass().getName(),ctx.getAttachment() != null ? ctx.getAttachment().getClass().getName() : "String_Node_Str"));
    if (ctx.getAttachment() == null) {
      log.warn(currentThread() + "String_Node_Str");
    }
  }
  if (ctx.getAttachment() instanceof DiscardEvent) {
    config.executorService().submit(new Callable<Boolean>(){
      public Boolean call(){
        try {
          ctx.getChannel().setReadable(true);
        }
 catch (        Exception ex) {
          if (log.isDebugEnabled()) {
            log.debug(ex);
          }
          connectionsPool.removeAllConnections(ctx.getChannel());
          return new Boolean(false);
        }
        return new Boolean(true);
      }
    }
).get();
    return;
  }
 else   if (ctx.getAttachment() instanceof AsyncCallable) {
    HttpChunk chunk=(HttpChunk)e.getMessage();
    if (chunk.isLast()) {
      AsyncCallable ac=(AsyncCallable)ctx.getAttachment();
      ctx.setAttachment(ac.future());
      ac.call();
    }
    return;
  }
 else   if (!(ctx.getAttachment() instanceof NettyResponseFuture<?>)) {
    return;
  }
  final NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
  future.touch();
  HttpRequest nettyRequest=future.getNettyRequest();
  AsyncHandler<?> handler=future.getAsyncHandler();
  try {
    if (e.getMessage() instanceof HttpResponse) {
      HttpResponse response=(HttpResponse)e.getMessage();
      if (log.isDebugEnabled()) {
        log.debug(String.format(currentThread() + "String_Node_Str",nettyRequest.toString(),response.toString()));
      }
      future.setHttpResponse(response);
      int statusCode=response.getStatus().getCode();
      String ka=response.getHeader(HttpHeaders.Names.CONNECTION);
      future.setKeepAlive(ka == null || ka.toLowerCase().equals("String_Node_Str"));
      String wwwAuth=response.getHeader(HttpHeaders.Names.WWW_AUTHENTICATE);
      Request request=future.getRequest();
      Realm realm=request.getRealm() != null ? request.getRealm() : config.getRealm();
      if (statusCode == 401 && wwwAuth != null && realm != null && !future.getAndSetAuth(true)) {
        final Realm nr=new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(URI.create(request.getUrl()).getPath()).setMethodName(request.getReqType()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth).build();
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (config.getKeepAlive()) {
          future.attachChannel(ctx.getChannel());
        }
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        future.setState(NettyResponseFuture.STATE.NEW);
        if (response.isChunked()) {
          ctx.setAttachment(new AsyncCallable(future){
            public Object call() throws Exception {
              nextRequest(builder.setRealm(nr).build(),future);
              return null;
            }
          }
);
        }
 else {
          nextRequest(builder.setRealm(nr).build(),future);
        }
        return;
      }
      String proxyAuth=response.getHeader(HttpHeaders.Names.PROXY_AUTHENTICATE);
      if (statusCode == 407 && proxyAuth != null && future.getRequest().getRealm() != null && !future.getAndSetAuth(true)) {
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (response.isChunked()) {
          ctx.setAttachment(new AsyncCallable(future){
            public Object call() throws Exception {
              nextRequest(future.getRequest(),future);
              return null;
            }
          }
);
        }
 else {
          nextRequest(future.getRequest(),future);
        }
        return;
      }
      if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) && statusCode == 200) {
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (config.getKeepAlive()) {
          future.attachChannel(ctx.getChannel());
        }
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        try {
          upgradeProtocol(ctx.getChannel().getPipeline(),(request.getUrl()));
        }
 catch (        Throwable ex) {
          abort(future,ex);
        }
        nextRequest(builder.build(),future);
        return;
      }
      boolean redirectEnabled=request.isRedirectEnabled() ? true : config.isRedirectEnabled();
      if (redirectEnabled && (statusCode == 302 || statusCode == 301)) {
        if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) {
          String location=response.getHeader(HttpHeaders.Names.LOCATION);
          if (location.startsWith("String_Node_Str")) {
            location=AsyncHttpProviderUtils.getBaseUrl(future.getURI()) + location;
          }
          if (!location.equalsIgnoreCase(future.getURI().toString())) {
            URI uri=AsyncHttpProviderUtils.createUri(location);
            final RequestBuilder builder=new RequestBuilder(future.getRequest());
            final URI initialConnectionUri=future.getURI();
            final boolean initialConnectionKeepAlive=future.getKeepAlive();
            future.setURI(uri);
            final String newUrl=uri.toString();
            if (log.isDebugEnabled()) {
              log.debug(String.format(currentThread() + "String_Node_Str",newUrl));
            }
            if (response.isChunked()) {
              ctx.setAttachment(new AsyncCallable(future){
                public Object call() throws Exception {
                  nextRequest(builder.setUrl(newUrl).build(),future);
                  if (initialConnectionKeepAlive) {
                    connectionsPool.addConnection(AsyncHttpProviderUtils.getBaseUrl(initialConnectionUri),ctx.getChannel());
                  }
 else {
                    closeChannel(ctx);
                  }
                  return null;
                }
              }
);
            }
 else {
              nextRequest(builder.setUrl(newUrl).build(),future);
              if (initialConnectionKeepAlive) {
                connectionsPool.addConnection(AsyncHttpProviderUtils.getBaseUrl(initialConnectionUri),ctx.getChannel());
              }
 else {
                closeChannel(ctx);
              }
            }
            return;
          }
        }
 else {
          throw new MaxRedirectException("String_Node_Str" + config.getMaxRedirects());
        }
      }
      if (!future.getAndSetStatusReceived(true) && updateStatusAndInterrupt(handler,new ResponseStatus(future.getURI(),response,this))) {
        finishUpdate(future,ctx,response.isChunked());
        return;
      }
 else       if (updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),response,this))) {
        finishUpdate(future,ctx,response.isChunked());
        return;
      }
 else       if (!response.isChunked()) {
        if (response.getContent().readableBytes() != 0) {
          updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),response,this));
        }
        finishUpdate(future,ctx,false);
        return;
      }
      if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) {
        markAsDoneAndCacheConnection(future,ctx,ctx.getChannel().isReadable());
      }
    }
 else     if (e.getMessage() instanceof HttpChunk) {
      HttpChunk chunk=(HttpChunk)e.getMessage();
      if (handler != null) {
        if (chunk.isLast() || updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),null,this,chunk))) {
          if (chunk instanceof DefaultHttpChunkTrailer) {
            updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),future.getHttpResponse(),this,(HttpChunkTrailer)chunk));
          }
          finishUpdate(future,ctx,!chunk.isLast());
        }
      }
    }
  }
 catch (  Exception t) {
    try {
      abort(future,t);
    }
  finally {
      finishUpdate(future,ctx,false);
      throw t;
    }
  }
}

Fixed version (ground truth):
@Override public void messageReceived(final ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  super.messageReceived(ctx,e);
  IN_IO_THREAD.set(Boolean.TRUE);
  if (log.isDebugEnabled()) {
    log.debug(String.format(currentThread() + "String_Node_Str",e.getClass().getName(),ctx.getAttachment() != null ? ctx.getAttachment().getClass().getName() : "String_Node_Str"));
    if (ctx.getAttachment() == null) {
      log.warn(currentThread() + "String_Node_Str");
    }
  }
  if (ctx.getAttachment() instanceof DiscardEvent) {
    config.executorService().submit(new Callable<Boolean>(){
      public Boolean call(){
        try {
          ctx.getChannel().setReadable(true);
        }
 catch (        Exception ex) {
          if (log.isDebugEnabled()) {
            log.debug(ex);
          }
          connectionsPool.removeAllConnections(ctx.getChannel());
          return new Boolean(false);
        }
        return new Boolean(true);
      }
    }
).get();
    return;
  }
 else   if (ctx.getAttachment() instanceof AsyncCallable) {
    HttpChunk chunk=(HttpChunk)e.getMessage();
    if (chunk.isLast()) {
      AsyncCallable ac=(AsyncCallable)ctx.getAttachment();
      ctx.setAttachment(ac.future());
      ac.call();
    }
    return;
  }
 else   if (!(ctx.getAttachment() instanceof NettyResponseFuture<?>)) {
    return;
  }
  final NettyResponseFuture<?> future=(NettyResponseFuture<?>)ctx.getAttachment();
  future.touch();
  HttpRequest nettyRequest=future.getNettyRequest();
  AsyncHandler<?> handler=future.getAsyncHandler();
  try {
    if (e.getMessage() instanceof HttpResponse) {
      HttpResponse response=(HttpResponse)e.getMessage();
      if (log.isDebugEnabled()) {
        log.debug(String.format(currentThread() + "String_Node_Str",nettyRequest.toString(),response.toString()));
      }
      future.setHttpResponse(response);
      int statusCode=response.getStatus().getCode();
      String ka=response.getHeader(HttpHeaders.Names.CONNECTION);
      future.setKeepAlive(ka == null || ka.toLowerCase().equals("String_Node_Str"));
      String wwwAuth=response.getHeader(HttpHeaders.Names.WWW_AUTHENTICATE);
      Request request=future.getRequest();
      Realm realm=request.getRealm() != null ? request.getRealm() : config.getRealm();
      if (statusCode == 401 && wwwAuth != null && realm != null && !future.getAndSetAuth(true)) {
        final Realm nr=new Realm.RealmBuilder().clone(realm).setScheme(realm.getAuthScheme()).setUri(URI.create(request.getUrl()).getPath()).setMethodName(request.getReqType()).setUsePreemptiveAuth(true).parseWWWAuthenticateHeader(wwwAuth).build();
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (config.getKeepAlive()) {
          future.attachChannel(ctx.getChannel());
        }
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        future.setState(NettyResponseFuture.STATE.NEW);
        if (response.isChunked()) {
          ctx.setAttachment(new AsyncCallable(future){
            public Object call() throws Exception {
              nextRequest(builder.setRealm(nr).build(),future);
              return null;
            }
          }
);
        }
 else {
          nextRequest(builder.setRealm(nr).build(),future);
        }
        return;
      }
      String proxyAuth=response.getHeader(HttpHeaders.Names.PROXY_AUTHENTICATE);
      if (statusCode == 407 && proxyAuth != null && future.getRequest().getRealm() != null && !future.getAndSetAuth(true)) {
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (response.isChunked()) {
          ctx.setAttachment(new AsyncCallable(future){
            public Object call() throws Exception {
              nextRequest(future.getRequest(),future);
              return null;
            }
          }
);
        }
 else {
          nextRequest(future.getRequest(),future);
        }
        return;
      }
      if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) && statusCode == 200) {
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        if (config.getKeepAlive()) {
          future.attachChannel(ctx.getChannel());
        }
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        try {
          upgradeProtocol(ctx.getChannel().getPipeline(),(request.getUrl()));
        }
 catch (        Throwable ex) {
          abort(future,ex);
        }
        nextRequest(builder.build(),future);
        return;
      }
      boolean redirectEnabled=request.isRedirectEnabled() ? true : config.isRedirectEnabled();
      if (redirectEnabled && (statusCode == 302 || statusCode == 301)) {
        if (future.incrementAndGetCurrentRedirectCount() < config.getMaxRedirects()) {
          future.getAndSetAuth(false);
          String location=response.getHeader(HttpHeaders.Names.LOCATION);
          if (location.startsWith("String_Node_Str")) {
            location=AsyncHttpProviderUtils.getBaseUrl(future.getURI()) + location;
          }
          if (!location.equalsIgnoreCase(future.getURI().toString())) {
            URI uri=AsyncHttpProviderUtils.createUri(location);
            final RequestBuilder builder=new RequestBuilder(future.getRequest());
            final URI initialConnectionUri=future.getURI();
            final boolean initialConnectionKeepAlive=future.getKeepAlive();
            future.setURI(uri);
            final String newUrl=uri.toString();
            if (log.isDebugEnabled()) {
              log.debug(String.format(currentThread() + "String_Node_Str",newUrl));
            }
            if (response.isChunked()) {
              ctx.setAttachment(new AsyncCallable(future){
                public Object call() throws Exception {
                  nextRequest(builder.setUrl(newUrl).build(),future);
                  if (initialConnectionKeepAlive) {
                    connectionsPool.addConnection(AsyncHttpProviderUtils.getBaseUrl(initialConnectionUri),ctx.getChannel());
                  }
 else {
                    closeChannel(ctx);
                  }
                  return null;
                }
              }
);
            }
 else {
              nextRequest(builder.setUrl(newUrl).build(),future);
              if (initialConnectionKeepAlive) {
                connectionsPool.addConnection(AsyncHttpProviderUtils.getBaseUrl(initialConnectionUri),ctx.getChannel());
              }
 else {
                closeChannel(ctx);
              }
            }
            return;
          }
        }
 else {
          throw new MaxRedirectException("String_Node_Str" + config.getMaxRedirects());
        }
      }
      if (!future.getAndSetStatusReceived(true) && updateStatusAndInterrupt(handler,new ResponseStatus(future.getURI(),response,this))) {
        finishUpdate(future,ctx,response.isChunked());
        return;
      }
 else       if (updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),response,this))) {
        finishUpdate(future,ctx,response.isChunked());
        return;
      }
 else       if (!response.isChunked()) {
        if (response.getContent().readableBytes() != 0) {
          updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),response,this));
        }
        finishUpdate(future,ctx,false);
        return;
      }
      if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) {
        markAsDoneAndCacheConnection(future,ctx,ctx.getChannel().isReadable());
      }
    }
 else     if (e.getMessage() instanceof HttpChunk) {
      HttpChunk chunk=(HttpChunk)e.getMessage();
      if (handler != null) {
        if (chunk.isLast() || updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),null,this,chunk))) {
          if (chunk instanceof DefaultHttpChunkTrailer) {
            updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),future.getHttpResponse(),this,(HttpChunkTrailer)chunk));
          }
          finishUpdate(future,ctx,!chunk.isLast());
        }
      }
    }
  }
 catch (  Exception t) {
    try {
      abort(future,t);
    }
  finally {
      finishUpdate(future,ctx,false);
      throw t;
    }
  }
}