https://bz.apache.org/bugzilla/show_bug.cgi?id=69862

            Bug ID: 69862
           Summary: NullPointerException in
                    JspServletWrapper.handleJspException masks original
                    exception when getRootCause() returns null
           Product: Tomcat 11
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Jasper
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: -------

Created attachment 40122
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=40122&action=edit
avoid NullPointerException when servletException.getRootCause is null

In JspServletWrapper.handleJspException(), when a ServletException has a null
root cause,
  the method assigns null to realException, causing a NullPointerException when
calling
  realException.getStackTrace(). This masks the original exception message.

  Location: java/org/apache/jasper/servlet/JspServletWrapper.java

  Current code (line ~615):
      Throwable realException = ex;
      if (ex instanceof ServletException) {
          realException = ((ServletException) ex).getRootCause();  // Can be
null
      }
      StackTraceElement[] frames = realException.getStackTrace();  // NPE if
null

  Reproduction:
  When a JSP throws a ServletException with no root cause (e.g., missing JSP
file),
  the actual error message like:
  "org.apache.jasper.JasperException: /WEB-INF/decorators/main.jsp (line: [29],
  column: [5]) JSP file [../pages/common/menu_oma.jsp] not found"

  is replaced by a NullPointerException with no useful information.

  Proposed fix:
      if (ex instanceof ServletException servletException &&
              servletException.getRootCause() instanceof Throwable rootCause) {
          realException = rootCause;
      }

  This ensures realException always contains a valid Throwable.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to