Program: 29466
Project: 29466
Buggy source:
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)) {
    wrapRequest(state);
    processRequest(request,response,state);
    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.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();
    RequestFacadeHelper reqFacHelper=RequestFacadeHelper.getInstance(wrequest);
    String originContextPath=null;
    if (reqFacHelper != null) {
      originContextPath=reqFacHelper.getContextPath(false);
    }
 else {
      originContextPath=wrequest.getContextPath();
    }
    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.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);
  ServletRequest sr=wrapRequest(state);
  wrapResponse(state);
  HttpServletRequest hrequest=state.hrequest;
  HttpServletResponse hresponse=state.hresponse;
  if ((hrequest == null) || (hresponse == null)) {
    processRequest(request,response,state);
  }
 else   if ((servletPath == null) && (pathInfo == null)) {
    ApplicationHttpRequest wrequest=(ApplicationHttpRequest)sr;
    wrequest.setRequestURI(hrequest.getRequestURI());
    wrequest.setContextPath(hrequest.getContextPath());
    wrequest.setServletPath(hrequest.getServletPath());
    wrequest.setPathInfo(hrequest.getPathInfo());
    wrequest.setQueryString(hrequest.getQueryString());
    processRequest(request,response,state);
  }
 else {
    ApplicationHttpRequest wrequest=(ApplicationHttpRequest)sr;
    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();
    RequestFacadeHelper reqFacHelper=RequestFacadeHelper.getInstance(wrequest);
    String originContextPath=null;
    if (reqFacHelper != null) {
      originContextPath=reqFacHelper.getContextPath(false);
    }
 else {
      originContextPath=wrequest.getContextPath();
    }
    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);
  }
  recycleRequestWrapper(state);
  unwrapRequest(state);
  unwrapResponse(state);
}