Program: 152
Project: 152
Buggy source:
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  super.messageReceived(ctx,e);
  if (ctx.getAttachment() instanceof DiscardEvent) {
    ctx.getChannel().setReadable(false);
    return;
  }
 else   if (ctx.getAttachment() instanceof Callable<?>) {
    HttpChunk chunk=(HttpChunk)e.getMessage();
    if (chunk.isLast()) {
      ((Callable)ctx.getAttachment()).call();
      ctx.setAttachment(null);
    }
    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();
      if (statusCode == 401 && wwwAuth != null && future.getRequest().getRealm() != null && !future.getAndSetAuth(true)) {
        final Realm realm=new Realm.RealmBuilder().clone(request.getRealm()).parseWWWAuthenticateHeader(wwwAuth).setUri(URI.create(request.getUrl()).getPath()).setMethodName(request.getReqType()).setScheme(request.getRealm().getAuthScheme()).setUsePreemptiveAuth(true).build();
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        future.attachChannel(ctx.getChannel());
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        if (response.isChunked()) {
          ctx.setAttachment(new Callable<Object>(){
            public Object call() throws Exception {
              execute(builder.setRealm(realm).build(),future);
              return null;
            }
          }
);
        }
 else {
          execute(builder.setRealm(realm).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 Callable<Object>(){
            public Object call() throws Exception {
              execute(future.getRequest(),future);
              return null;
            }
          }
);
        }
 else {
          execute(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()));
        }
        future.attachChannel(ctx.getChannel());
        RequestBuilder builder=new RequestBuilder(future.getRequest());
        try {
          upgradeProtocol(ctx.getChannel().getPipeline(),(request.getUrl()));
        }
 catch (        Throwable ex) {
          abort(future,ex);
        }
        execute(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);
            if (location.startsWith("String_Node_Str")) {
              upgradeProtocol(ctx.getChannel().getPipeline(),"String_Node_Str");
            }
            final RequestBuilder builder=new RequestBuilder(future.getRequest());
            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 Callable<Object>(){
                public Object call() throws Exception {
                  execute(builder.setUrl(newUrl).build(),future,false);
                  return null;
                }
              }
);
            }
 else {
              execute(builder.setUrl(newUrl).build(),future,false);
            }
            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);
        return;
      }
 else       if (updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),response,this))) {
        finishUpdate(future,ctx);
        return;
      }
 else       if (!response.isChunked()) {
        if (response.getContent().readableBytes() != 0) {
          updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),response,this));
        }
        finishUpdate(future,ctx);
        return;
      }
      if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) {
        markAsDoneAndCacheConnection(future,ctx,true);
      }
    }
 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);
        }
      }
    }
  }
 catch (  Exception t) {
    try {
      abort(future,t);
    }
  finally {
      finishUpdate(future,ctx);
      throw t;
    }
  }
}

Fixed version (ground truth):
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  super.messageReceived(ctx,e);
  if (log.isDebugEnabled()) {
    log.debug(String.format(currentThread() + "String_Node_Str",e.getClass().getName(),ctx.getAttachment().getClass().getName()));
  }
  if (ctx.getAttachment() instanceof DiscardEvent) {
    ctx.getChannel().setReadable(false);
    return;
  }
 else   if (ctx.getAttachment() instanceof AsyncCallable) {
    HttpChunk chunk=(HttpChunk)e.getMessage();
    if (chunk.isLast()) {
      ((AsyncCallable)ctx.getAttachment()).call();
      ctx.setAttachment(null);
    }
    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();
      if (statusCode == 401 && wwwAuth != null && future.getRequest().getRealm() != null && !future.getAndSetAuth(true)) {
        final Realm realm=new Realm.RealmBuilder().clone(request.getRealm()).parseWWWAuthenticateHeader(wwwAuth).setUri(URI.create(request.getUrl()).getPath()).setMethodName(request.getReqType()).setScheme(request.getRealm().getAuthScheme()).setUsePreemptiveAuth(true).build();
        if (log.isDebugEnabled()) {
          log.debug(String.format(currentThread() + "String_Node_Str",request.getUrl()));
        }
        future.attachChannel(ctx.getChannel());
        final RequestBuilder builder=new RequestBuilder(future.getRequest());
        if (response.isChunked()) {
          ctx.setAttachment(new AsyncCallable(future){
            public Object call() throws Exception {
              execute(builder.setRealm(realm).build(),future);
              return null;
            }
          }
);
        }
 else {
          execute(builder.setRealm(realm).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 {
              execute(future.getRequest(),future);
              return null;
            }
          }
);
        }
 else {
          execute(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()));
        }
        future.attachChannel(ctx.getChannel());
        RequestBuilder builder=new RequestBuilder(future.getRequest());
        try {
          upgradeProtocol(ctx.getChannel().getPipeline(),(request.getUrl()));
        }
 catch (        Throwable ex) {
          abort(future,ex);
        }
        execute(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);
            if (location.startsWith("String_Node_Str")) {
              upgradeProtocol(ctx.getChannel().getPipeline(),"String_Node_Str");
            }
            final RequestBuilder builder=new RequestBuilder(future.getRequest());
            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 {
                  execute(builder.setUrl(newUrl).build(),future,false);
                  return null;
                }
              }
);
            }
 else {
              execute(builder.setUrl(newUrl).build(),future,false);
            }
            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);
        return;
      }
 else       if (updateHeadersAndInterrupt(handler,new ResponseHeaders(future.getURI(),response,this))) {
        finishUpdate(future,ctx);
        return;
      }
 else       if (!response.isChunked()) {
        if (response.getContent().readableBytes() != 0) {
          updateBodyAndInterrupt(handler,new ResponseBodyPart(future.getURI(),response,this));
        }
        finishUpdate(future,ctx);
        return;
      }
      if (nettyRequest.getMethod().equals(HttpMethod.HEAD)) {
        markAsDoneAndCacheConnection(future,ctx,true);
      }
    }
 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);
        }
      }
    }
  }
 catch (  Exception t) {
    try {
      abort(future,t);
    }
  finally {
      finishUpdate(future,ctx);
      throw t;
    }
  }
}