Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-6443

RequestDispatchUtil swallows any exception at forward

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Do
    • Icon: Critical Critical
    • None
    • 5.4.1, 5.4.3
    • None

      use case: in any page reached through a virtualuri where you may have an error... the error is logged but the result for the user is always a blank page, the error page is never shown and there is no way to handle that error as expected.

      This is due to the way RequestDispatchUtil handles exceptions after forwards:

              if (targetUri.startsWith(FORWARD_PREFIX)) {
                  String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
                  try {
                      request.getRequestDispatcher(forwardUrl).forward(request, response);
                  } catch (Exception e) {
                      log.error("Failed to forward to {} - {}:{}", forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage());
                  }
                  return true;
              }
      

      As you can see there is a "catch Exception" which logs and ignores, just returning true like for successful requests.

      I would propose to change the catch by simply rethrowing runtime exceptions, e.g.

              if (targetUri.startsWith(FORWARD_PREFIX))
              {
                  String forwardUrl = StringUtils.substringAfter(targetUri, FORWARD_PREFIX);
                  try
                  {
                      request.getRequestDispatcher(forwardUrl).forward(request, response);
                  }
                  catch (RuntimeException e)
                  {
                      log.error("Failed to forward to {} - {}:{}", new Object[]
                      { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
                      throw e;
                  }
                  catch (Exception e)
                  {
                      log.error("Failed to forward to {} - {}:{}", new Object[]
                      { forwardUrl, ClassUtils.getShortClassName(e.getClass()), e.getMessage() });
                      throw new RuntimeException(e);
                  }
                  return true;
              }
      

      with this patch the error page is properly displayed (or the exception can be handled in other ways if needed)

        Acceptance criteria

              Unassigned Unassigned
              fgiust Fabrizio Giustina
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:

                  Bug DoR
                  Task DoD