Program: 28578
Project: 28578
Buggy source:
private void doInvoke(Request request,Response response,boolean chaining) throws IOException, ServletException {
  if ((valves.length > 0) || (basic != null)) {
    int status=GlassFishValve.INVOKE_NEXT;
    int i;
    for (i=0; i < valves.length; i++) {
      Request req=request;
      Response resp=response;
      if (chaining) {
        req=getRequest(request);
        resp=getResponse(request,response);
      }
      status=valves[i].invoke(req,resp);
      if (status != GlassFishValve.INVOKE_NEXT)       break;
    }
    GlassFishValve[] savedValves=valves;
    if (status == GlassFishValve.INVOKE_NEXT) {
      if (firstTcValve != null) {
        firstTcValve.invoke((org.apache.catalina.connector.Request)request,(org.apache.catalina.connector.Response)response);
      }
 else       if (basic != null) {
        Request req=request;
        Response resp=response;
        if (chaining) {
          req=getRequest(request);
          resp=getResponse(request,response);
        }
        basic.invoke(req,resp);
        basic.postInvoke(req,resp);
      }
    }
    for (int j=i - 1; j >= 0; j--) {
      Request req=request;
      Response resp=response;
      if (chaining) {
        req=getRequest(request);
        resp=getResponse(request,response);
      }
      savedValves[j].postInvoke(req,resp);
    }
    savedValves=null;
  }
 else {
    throw new ServletException(rb.getString(NO_VALVES_IN_PIPELINE_EXCEPTION));
  }
  if (request instanceof org.apache.catalina.connector.Request) {
    org.apache.catalina.connector.Request req=(org.apache.catalina.connector.Request)request;
    if (req.isUpgrade()) {
      HttpUpgradeHandler handler=req.getHttpUpgradeHandler();
      if (handler != null) {
        WebConnectionImpl wc=new WebConnectionImpl(req.getInputStream(),((org.apache.catalina.connector.Response)req.getResponse()).getOutputStream());
        wc.setRequest(req);
        if (response instanceof org.apache.catalina.connector.Response) {
          wc.setResponse((org.apache.catalina.connector.Response)response);
        }
        handler.init(wc);
      }
 else {
        log.log(Level.SEVERE,PROTOCOL_HANDLER_REQUIRED_EXCEPTION);
      }
    }
  }
}

Fixed version (ground truth):
private void doInvoke(Request request,Response response,boolean chaining) throws IOException, ServletException {
  if ((valves.length > 0) || (basic != null)) {
    int status=GlassFishValve.INVOKE_NEXT;
    int i;
    for (i=0; i < valves.length; i++) {
      Request req=request;
      Response resp=response;
      if (chaining) {
        req=getRequest(request);
        resp=getResponse(request,response);
      }
      status=valves[i].invoke(req,resp);
      if (status != GlassFishValve.INVOKE_NEXT)       break;
    }
    GlassFishValve[] savedValves=valves;
    if (status == GlassFishValve.INVOKE_NEXT) {
      if (firstTcValve != null) {
        firstTcValve.invoke((org.apache.catalina.connector.Request)request,(org.apache.catalina.connector.Response)response);
      }
 else       if (basic != null) {
        Request req=request;
        Response resp=response;
        if (chaining) {
          req=getRequest(request);
          resp=getResponse(request,response);
        }
        basic.invoke(req,resp);
        basic.postInvoke(req,resp);
      }
    }
    for (int j=i - 1; j >= 0; j--) {
      Request req=request;
      Response resp=response;
      if (chaining) {
        req=getRequest(request);
        resp=getResponse(request,response);
      }
      savedValves[j].postInvoke(req,resp);
    }
    savedValves=null;
  }
 else {
    throw new ServletException(rb.getString(NO_VALVES_IN_PIPELINE_EXCEPTION));
  }
  if (request instanceof org.apache.catalina.connector.Request) {
    org.apache.catalina.connector.Request req=(org.apache.catalina.connector.Request)request;
    if (req.isUpgrade()) {
      HttpUpgradeHandler handler=req.getHttpUpgradeHandler();
      if (handler != null) {
        WebConnectionImpl wc=new WebConnectionImpl(req.getInputStream(),((org.apache.catalina.connector.Response)req.getResponse()).getOutputStream());
        wc.setRequest(req);
        req.setWebConnection(wc);
        if (response instanceof org.apache.catalina.connector.Response) {
          wc.setResponse((org.apache.catalina.connector.Response)response);
        }
        handler.init(wc);
      }
 else {
        log.log(Level.SEVERE,PROTOCOL_HANDLER_REQUIRED_EXCEPTION);
      }
    }
  }
}