Program: 29465
Project: 29465
Buggy source:
/** 
 * Ask the resource represented by this RequestDispatcher to process the associated request, and create (or append to) the associated response. <p> <strong>IMPLEMENTATION NOTE</strong>: This implementation assumes that no filters are applied to a forwarded or included resource, because they were already done for the original request.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param crossContext true if the request dispatch is crossing contextboundaries, false otherwise
 * @param state the state of this ApplicationDispatcher
 * @throws IOException if an input/output error occurs
 * @throws ServletException if a servlet error occurs
 */
private void doInvoke(ServletRequest request,ServletResponse response,boolean crossContext,State state) throws IOException, ServletException {
  ClassLoader oldCCL=null;
  if (crossContext) {
    oldCCL=Thread.currentThread().getContextClassLoader();
    ClassLoader contextClassLoader=context.getLoader().getClassLoader();
    Thread.currentThread().setContextClassLoader(contextClassLoader);
  }
  HttpServletResponse hresponse=null;
  if (response instanceof HttpServletResponse) {
    hresponse=(HttpServletResponse)response;
  }
  Servlet servlet=null;
  IOException ioException=null;
  ServletException servletException=null;
  RuntimeException runtimeException=null;
  boolean unavailable=false;
  if (wrapper.isUnavailable()) {
    log(sm.getString("String_Node_Str",wrapper.getName()));
    if (hresponse == null) {
      ;
    }
 else {
      long available=wrapper.getAvailable();
      if ((available > 0L) && (available < Long.MAX_VALUE))       hresponse.setDateHeader("String_Node_Str",available);
      hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,sm.getString("String_Node_Str",wrapper.getName()));
    }
    unavailable=true;
  }
  try {
    if (!unavailable) {
      servlet=wrapper.allocate();
    }
  }
 catch (  ServletException e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),StandardWrapper.getRootCause(e));
    servletException=e;
    servlet=null;
  }
catch (  Throwable e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=new ServletException(sm.getString("String_Node_Str",wrapper.getName()),e);
    servlet=null;
  }
  ApplicationFilterFactory factory=ApplicationFilterFactory.getInstance();
  ApplicationFilterChain filterChain=factory.createFilterChain(request,wrapper,servlet);
  InstanceSupport support=((StandardWrapper)wrapper).getInstanceSupport();
  RequestFacadeHelper reqFacHelper=RequestFacadeHelper.getInstance(request);
  try {
    String jspFile=wrapper.getJspFile();
    if (jspFile != null) {
      request.setAttribute(Globals.JSP_FILE_ATTR,jspFile);
    }
    support.fireInstanceEvent(InstanceEvent.EventType.BEFORE_DISPATCH_EVENT,servlet,request,response);
    if (servlet != null) {
      if (reqFacHelper != null) {
        reqFacHelper.incrementDispatchDepth();
        if (reqFacHelper.isMaxDispatchDepthReached()) {
          throw new ServletException(sm.getString("String_Node_Str",new Object[]{Integer.valueOf(Request.getMaxDispatchDepth())}));
        }
      }
      if (filterChain != null) {
        filterChain.setWrapper((StandardWrapper)wrapper);
        filterChain.doFilter(request,response);
      }
 else {
        ((StandardWrapper)wrapper).service(request,response,servlet);
      }
    }
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
  }
 catch (  ClientAbortException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    ioException=e;
  }
catch (  IOException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    ioException=e;
  }
catch (  UnavailableException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=e;
    wrapper.unavailable(e);
  }
catch (  ServletException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    Throwable rootCause=StandardWrapper.getRootCause(e);
    if (!(rootCause instanceof ClientAbortException)) {
      log(sm.getString("String_Node_Str",wrapper.getName()),rootCause);
    }
    servletException=e;
  }
catch (  RuntimeException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    runtimeException=e;
  }
 finally {
    if (reqFacHelper != null) {
      reqFacHelper.decrementDispatchDepth();
    }
  }
  try {
    if (filterChain != null)     filterChain.release();
  }
 catch (  Throwable e) {
    log.log(Level.SEVERE,sm.getString("String_Node_Str",wrapper.getName()),e);
  }
  try {
    if (servlet != null) {
      wrapper.deallocate(servlet);
    }
  }
 catch (  ServletException e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=e;
  }
catch (  Throwable e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=new ServletException(sm.getString("String_Node_Str",wrapper.getName()),e);
  }
  if (oldCCL != null)   Thread.currentThread().setContextClassLoader(oldCCL);
  if (ioException != null)   throw ioException;
  if (servletException != null)   throw servletException;
  if (runtimeException != null)   throw runtimeException;
}

Fixed version (ground truth):
/** 
 * Ask the resource represented by this RequestDispatcher to process the associated request, and create (or append to) the associated response. <p> <strong>IMPLEMENTATION NOTE</strong>: This implementation assumes that no filters are applied to a forwarded or included resource, because they were already done for the original request.
 * @param request The servlet request we are processing
 * @param response The servlet response we are creating
 * @param crossContext true if the request dispatch is crossing contextboundaries, false otherwise
 * @param state the state of this ApplicationDispatcher
 * @throws IOException if an input/output error occurs
 * @throws ServletException if a servlet error occurs
 */
private void doInvoke(ServletRequest request,ServletResponse response,boolean crossContext,State state) throws IOException, ServletException {
  ClassLoader oldCCL=null;
  if (crossContext) {
    oldCCL=Thread.currentThread().getContextClassLoader();
    ClassLoader contextClassLoader=context.getLoader().getClassLoader();
    Thread.currentThread().setContextClassLoader(contextClassLoader);
  }
  HttpServletResponse hresponse=state.hresponse;
  Servlet servlet=null;
  IOException ioException=null;
  ServletException servletException=null;
  RuntimeException runtimeException=null;
  boolean unavailable=false;
  if (wrapper.isUnavailable()) {
    log(sm.getString("String_Node_Str",wrapper.getName()));
    if (hresponse == null) {
      ;
    }
 else {
      long available=wrapper.getAvailable();
      if ((available > 0L) && (available < Long.MAX_VALUE))       hresponse.setDateHeader("String_Node_Str",available);
      hresponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,sm.getString("String_Node_Str",wrapper.getName()));
    }
    unavailable=true;
  }
  try {
    if (!unavailable) {
      servlet=wrapper.allocate();
    }
  }
 catch (  ServletException e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),StandardWrapper.getRootCause(e));
    servletException=e;
    servlet=null;
  }
catch (  Throwable e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=new ServletException(sm.getString("String_Node_Str",wrapper.getName()),e);
    servlet=null;
  }
  ApplicationFilterFactory factory=ApplicationFilterFactory.getInstance();
  ApplicationFilterChain filterChain=factory.createFilterChain(request,wrapper,servlet);
  InstanceSupport support=((StandardWrapper)wrapper).getInstanceSupport();
  RequestFacadeHelper reqFacHelper=RequestFacadeHelper.getInstance(request);
  try {
    String jspFile=wrapper.getJspFile();
    if (jspFile != null) {
      request.setAttribute(Globals.JSP_FILE_ATTR,jspFile);
    }
    support.fireInstanceEvent(InstanceEvent.EventType.BEFORE_DISPATCH_EVENT,servlet,request,response);
    if (servlet != null) {
      if (reqFacHelper != null) {
        reqFacHelper.incrementDispatchDepth();
        if (reqFacHelper.isMaxDispatchDepthReached()) {
          throw new ServletException(sm.getString("String_Node_Str",new Object[]{Integer.valueOf(Request.getMaxDispatchDepth())}));
        }
      }
      if (filterChain != null) {
        filterChain.setWrapper((StandardWrapper)wrapper);
        filterChain.doFilter(request,response);
      }
 else {
        ((StandardWrapper)wrapper).service(request,response,servlet);
      }
    }
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
  }
 catch (  ClientAbortException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    ioException=e;
  }
catch (  IOException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    ioException=e;
  }
catch (  UnavailableException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=e;
    wrapper.unavailable(e);
  }
catch (  ServletException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    Throwable rootCause=StandardWrapper.getRootCause(e);
    if (!(rootCause instanceof ClientAbortException)) {
      log(sm.getString("String_Node_Str",wrapper.getName()),rootCause);
    }
    servletException=e;
  }
catch (  RuntimeException e) {
    support.fireInstanceEvent(AFTER_DISPATCH_EVENT,servlet,request,response);
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    runtimeException=e;
  }
 finally {
    if (reqFacHelper != null) {
      reqFacHelper.decrementDispatchDepth();
    }
  }
  try {
    if (filterChain != null)     filterChain.release();
  }
 catch (  Throwable e) {
    log.log(Level.SEVERE,sm.getString("String_Node_Str",wrapper.getName()),e);
  }
  try {
    if (servlet != null) {
      wrapper.deallocate(servlet);
    }
  }
 catch (  ServletException e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=e;
  }
catch (  Throwable e) {
    log(sm.getString("String_Node_Str",wrapper.getName()),e);
    servletException=new ServletException(sm.getString("String_Node_Str",wrapper.getName()),e);
  }
  if (oldCCL != null)   Thread.currentThread().setContextClassLoader(oldCCL);
  if (ioException != null)   throw ioException;
  if (servletException != null)   throw servletException;
  if (runtimeException != null)   throw runtimeException;
}