Program: 158
Project: 158
Buggy source:
@Override public void messageReceived(ChannelHandlerContext ctx,MessageEvent e) throws Exception {
  if (ctx.getAttachment() instanceof DiscardEvent) {
    ctx.getChannel().setReadable(false);
    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();
      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)) {
        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("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        RequestBuilder builder=new RequestBuilder(future.getRequest());
        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("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        execute(future.getRequest(),future);
        return;
      }
      if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) && statusCode == 200) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        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.equals(future.getURI().toString())) {
            URI uri=AsyncHttpProviderUtils.createUri(location);
            if (location.startsWith("String_Node_Str")) {
              upgradeProtocol(ctx.getChannel().getPipeline(),"String_Node_Str");
            }
            RequestBuilder builder=new RequestBuilder(future.getRequest());
            future.setURI(uri);
            markChannelNotReadable(ctx);
            String newUrl=uri.toString();
            if (log.isDebugEnabled()) {
              log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",newUrl));
            }
            execute(builder.setUrl(newUrl).build(),future);
            return;
          }
        }
 else {
          throw new MaxRedirectException("String_Node_Str" + config.getMaxRedirects());
        }
      }
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",response.getStatus()));
        log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",response.getProtocolVersion()));
        log.debug("String_Node_Str");
        if (!response.getHeaderNames().isEmpty()) {
          for (          String name : response.getHeaderNames()) {
            log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",name,response.getHeaders(name)));
          }
          log.debug("String_Node_Str");
        }
      }
      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 {
  if (ctx.getAttachment() instanceof DiscardEvent) {
    ctx.getChannel().setReadable(false);
    return;
  }
 else   if (!(ctx.getAttachment() instanceof NettyResponseFuture<?>)) {
    return;
  }
  super.messageReceived(ctx,e);
  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();
      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)) {
        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("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        RequestBuilder builder=new RequestBuilder(future.getRequest());
        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("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        execute(future.getRequest(),future);
        return;
      }
      if (future.getNettyRequest().getMethod().equals(HttpMethod.CONNECT) && statusCode == 200) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",request.getUrl()));
        }
        markAsDoneAndCacheConnection(future,ctx,false);
        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.equals(future.getURI().toString())) {
            URI uri=AsyncHttpProviderUtils.createUri(location);
            if (location.startsWith("String_Node_Str")) {
              upgradeProtocol(ctx.getChannel().getPipeline(),"String_Node_Str");
            }
            RequestBuilder builder=new RequestBuilder(future.getRequest());
            future.setURI(uri);
            markChannelNotReadable(ctx);
            String newUrl=uri.toString();
            if (log.isDebugEnabled()) {
              log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",newUrl));
            }
            execute(builder.setUrl(newUrl).build(),future);
            return;
          }
        }
 else {
          throw new MaxRedirectException("String_Node_Str" + config.getMaxRedirects());
        }
      }
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",response.getStatus()));
        log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",response.getProtocolVersion()));
        log.debug("String_Node_Str");
        if (!response.getHeaderNames().isEmpty()) {
          for (          String name : response.getHeaderNames()) {
            log.debug(String.format("String_Node_Str" + Thread.currentThread().getName() + "String_Node_Str",name,response.getHeaders(name)));
          }
          log.debug("String_Node_Str");
        }
      }
      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;
    }
  }
}