Program: 30382
Project: 30382
Buggy source:
private void doDispatch(ServletRequest request,ServletResponse response,DispatcherType dispatcherType) throws ServletException, IOException {
  if (!DispatcherType.ASYNC.equals(dispatcherType)) {
    if (response.isCommitted()) {
      if (log.isLoggable(Level.FINE))       log.fine("String_Node_Str");
      throw new IllegalStateException(sm.getString("String_Node_Str"));
    }
    try {
      response.resetBuffer();
    }
 catch (    IllegalStateException e) {
      if (log.isLoggable(Level.FINE))       log.fine("String_Node_Str" + e);
      throw e;
    }
  }
  State state=new State(request,response,dispatcherType);
  HttpServletRequest hrequest=null;
  if (request instanceof HttpServletRequest) {
    hrequest=(HttpServletRequest)request;
  }
  HttpServletResponse hresponse=null;
  if (response instanceof HttpServletResponse) {
    hresponse=(HttpServletResponse)response;
  }
  if ((hrequest == null) || (hresponse == null)) {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    processRequest(request,response,state,wrequest.getRequestFacade());
    unwrapRequest(state);
  }
 else   if ((servletPath == null) && (pathInfo == null)) {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    wrequest.setRequestURI(hrequest.getRequestURI());
    wrequest.setContextPath(hrequest.getContextPath());
    wrequest.setServletPath(hrequest.getServletPath());
    wrequest.setPathInfo(hrequest.getPathInfo());
    wrequest.setQueryString(hrequest.getQueryString());
    processRequest(request,response,state,wrequest.getRequestFacade());
    wrequest.recycle();
    unwrapRequest(state);
  }
 else {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    if ((DispatcherType.FORWARD.equals(dispatcherType) && hrequest.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) == null) || (DispatcherType.ASYNC.equals(dispatcherType) && hrequest.getAttribute(AsyncContext.ASYNC_REQUEST_URI) == null)) {
      wrequest.initSpecialAttributes(hrequest.getRequestURI(),hrequest.getContextPath(),hrequest.getServletPath(),hrequest.getPathInfo(),hrequest.getQueryString());
    }
    String targetContextPath=context.getPath();
    RequestFacade requestFacade=wrequest.getRequestFacade();
    String originContextPath=requestFacade.getContextPath(false);
    if (originContextPath != null && originContextPath.equals(targetContextPath)) {
      targetContextPath=hrequest.getContextPath();
    }
    wrequest.setContextPath(targetContextPath);
    wrequest.setRequestURI(requestURI);
    wrequest.setServletPath(servletPath);
    wrequest.setPathInfo(pathInfo);
    if (queryString != null) {
      wrequest.setQueryString(queryString);
      wrequest.setQueryParams(queryString);
    }
    processRequest(request,response,state,wrequest.getRequestFacade());
    wrequest.recycle();
    unwrapRequest(state);
  }
}

Fixed version (ground truth):
private void doDispatch(ServletRequest request,ServletResponse response,DispatcherType dispatcherType) throws ServletException, IOException {
  if (DispatcherType.ASYNC != dispatcherType) {
    if (response.isCommitted()) {
      if (log.isLoggable(Level.FINE))       log.fine("String_Node_Str");
      throw new IllegalStateException(sm.getString("String_Node_Str"));
    }
    try {
      response.resetBuffer();
    }
 catch (    IllegalStateException e) {
      if (log.isLoggable(Level.FINE))       log.fine("String_Node_Str" + e);
      throw e;
    }
  }
  if (DispatcherType.INCLUDE != dispatcherType) {
    DispatchTargetsInfo dtInfo=(DispatchTargetsInfo)request.getAttribute(LAST_DISPATCH_REQUEST_PATH_ATTR);
    if (dtInfo == null) {
      dtInfo=new DispatchTargetsInfo();
      request.setAttribute(LAST_DISPATCH_REQUEST_PATH_ATTR,dtInfo);
    }
    if (servletPath == null && pathInfo == null) {
      dtInfo.addDispatchTarget(wrapper.getServletName(),true);
    }
 else {
      dtInfo.addDispatchTarget(getCombinedPath(),false);
    }
  }
  State state=new State(request,response,dispatcherType);
  HttpServletRequest hrequest=null;
  if (request instanceof HttpServletRequest) {
    hrequest=(HttpServletRequest)request;
  }
  HttpServletResponse hresponse=null;
  if (response instanceof HttpServletResponse) {
    hresponse=(HttpServletResponse)response;
  }
  if ((hrequest == null) || (hresponse == null)) {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    processRequest(request,response,state,wrequest.getRequestFacade());
    unwrapRequest(state);
  }
 else   if ((servletPath == null) && (pathInfo == null)) {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    wrequest.setRequestURI(hrequest.getRequestURI());
    wrequest.setContextPath(hrequest.getContextPath());
    wrequest.setServletPath(hrequest.getServletPath());
    wrequest.setPathInfo(hrequest.getPathInfo());
    wrequest.setQueryString(hrequest.getQueryString());
    processRequest(request,response,state,wrequest.getRequestFacade());
    wrequest.recycle();
    unwrapRequest(state);
  }
 else {
    ApplicationHttpRequest wrequest=wrapRequest(state);
    if ((DispatcherType.FORWARD == dispatcherType && hrequest.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) == null) || (DispatcherType.ASYNC == dispatcherType && hrequest.getAttribute(AsyncContext.ASYNC_REQUEST_URI) == null)) {
      wrequest.initSpecialAttributes(hrequest.getRequestURI(),hrequest.getContextPath(),hrequest.getServletPath(),hrequest.getPathInfo(),hrequest.getQueryString());
    }
    String targetContextPath=context.getPath();
    RequestFacade requestFacade=wrequest.getRequestFacade();
    String originContextPath=requestFacade.getContextPath(false);
    if (originContextPath != null && originContextPath.equals(targetContextPath)) {
      targetContextPath=hrequest.getContextPath();
    }
    wrequest.setContextPath(targetContextPath);
    wrequest.setRequestURI(requestURI);
    wrequest.setServletPath(servletPath);
    wrequest.setPathInfo(pathInfo);
    if (queryString != null) {
      wrequest.setQueryString(queryString);
      wrequest.setQueryParams(queryString);
    }
    processRequest(request,response,state,wrequest.getRequestFacade());
    wrequest.recycle();
    unwrapRequest(state);
  }
}