I'm running Tomcat 5.0.28 and running into a problem during forward to
the error page.  Specifically, I'm seeing a NullPointerException and I'm
losing the original exception which I'd like to track.

 

When looking into the source code, in JspServlet.service(), I see the
following:

 

        try {

            String includeUri 

                = (String)
request.getAttribute(Constants.INC_SERVLET_PATH);

            String requestUri 

                = (String)
request.getAttribute(Constants.INC_REQUEST_URI);

            

            String jspUri;

            

            // When jsp-property-group/url-matching is used, and when
the 

            // jsp is not defined with <servlet-name>, the url

            // as to be passed as it is to the JSP container (since 

            // Catalina doesn't know anything about the requested JSP 

            

            // The first scenario occurs when the jsp is not directly
under /

            // example: /utf16/foo.jsp

            if (requestUri != null){

                String currentIncludedUri 

                    =
requestUri.substring(requestUri.indexOf(includeUri));  <--

 

                if ( !includeUri.equals(currentIncludedUri) ) {

                    includeUri = currentIncludedUri;

                }

            }

            

            ...

 

What appears to be happening, is that the requestUri is set to the URI
of the page on which the exception originally occurred and the
includeUri is null.  Therefore, when requestUri.indexOf(includeUri) is
invoked, a NullPointerException occurs.

 

The only info I've been able to find out, is that in PageContextImpl
during the handlePageException() method, forward() is invoked to forward
to the error page.  In the doForward() method, the attribute for the
include uri (Constants.INC_SERVLET_PATH) above is removed.  This leads
to it being null.  However, I don't see the other attribute ever being
removed.

 

So, the question is, what is the expected behavior of these two
attributes?  I believe that they should both be null for a forward (in
this case to the error page), correct?  Is there something that I can do
to avoid this NullPointerException?  Is it a bug which has been resolved
in future releases?

 

Thanks for the information.

 

Scott

Reply via email to