tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Karen Lease <kle...@vftis.com>
Subject BUG? Include from JSP and <error-page>
Date Wed, 10 May 2000 15:34:27 GMT
Hi everybody,

I believe I have found a bug in the 3.1 release version of Tomcat, but 
the buglist page refuses any access, so I will discuss it here.

Here is what happens.
I have an error-page specified in my web.xml. It's working fine, if the 
error is generated directly by a servlet. However when I force an error 
in a servlet which is included from a jsp page, I get back the stack 
trace shown below. My JSP has already generated some output before 
calling the servlet, so the response is committed. What I found strange 
was that the "root cause" was NullPointerException. My error page is 
not even being reached, and the exception was coming from 
tomcat.core.ContextManager.handleError(). The reason is that in this 
method, in the case of handling an error page for an Exception, the 
code calls reset() on the Response before looking to see if the 
response was committed. This causes the IllegalStateException, which 
gets caught. But then the method "falls through" to the default error 
page handling, except that errorServlet is still null. So when it tries 
to pass off to that, it generates the NullPointerException which I was 
getting. I included the code below, with the fixes I made to stop it 
from doing that.

I just looked at the latest version of ContextManager.java from CVS 
(1.78), which has a lot of new stuff, including some restructured error 
handling code. I believe it will no longer generate the 
IllegalStateException because the reset is gone. But if there is some 
other exception generated by the error page itself, it will still fall 
through with a null errorServlet reference.

Note: the relevant code is now in the method: "private void 
callInternalError(  )"


--------------------------------------------------------------------  
-------------------------------------------
STACK TRACE in my browser window
--------------------------------------------------------------------  
-------------------------------------------
Included servlet error: 500

Location: /<myjsp>

Internal Servlet Error:

javax.servlet.ServletException
        at 
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageCo  
ntextImpl.java:386)
        at 
jsp._0002fjsp_0002fSearchResult_0002ejspSearchResult_jsp_0._jspServi  
ce(_0002fjsp_0002fSearchResult_0002ejspSearchResult_jsp_0.java:79)
        at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspSe  
rvlet.java:174)
        at 
org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:  
261)
        at 
org.apache.jasper.runtime.JspServlet.service(JspServlet.java, Compiled 
Code)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.j  
ava, Compiled Code)
        at org.apache.tomcat.core.RequestDispatcherImpl.forward(Requ  
estDispatcherImpl.java:163)
        at <mypackage>.SearchServlet.doGet(SearchServlet.java:48)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.j  
ava, Compiled Code)
        at 
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at 
org.apache.tomcat.service.http.HttpConnectionHandler.processConnecti  
on(HttpConnectionHandler.java:160)
        at 
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.  
java:338)
        at java.lang.Thread.run(Thread.java:479)

Root cause:

java.lang.NullPointerException
        at 
org.apache.tomcat.core.ContextManager.handleError(ContextManager.java, 
Compiled Code)
        at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.j  
ava, Compiled Code)
        at 
org.apache.tomcat.core.RequestDispatcherImpl.include(RequestDispatch  
erImpl.java:262)
        at 
org.apache.jasper.runtime.PageContextImpl.include(PageContextImpl.ja  
va:350)
        at 
jsp._0002fjsp_0002fSearchResult_0002ejspSearchResult_jsp_0._jspServi  
ce(_0002fjsp_0002fSearchResult_0002ejspSearchResult_jsp_0.java:69)
        at 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspSe  
rvlet.java:174)
        at 
org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:  
261)
        at 
org.apache.jasper.runtime.JspServlet.service(JspServlet.java, Compiled 
Code)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.j  
ava, Compiled Code)
        at org.apache.tomcat.core.RequestDispatcherImpl.forward(Requ  
estDispatcherImpl.java:163)
        at <mypackage>.SearchServlet.doGet(SearchServlet.java:48)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at 
org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.j  
ava, Compiled Code)
        at 
org.apache.tomcat.core.ContextManager.service(ContextManager.java:559)
        at 
org.apache.tomcat.service.http.HttpConnectionHandler.processConnecti  
on(HttpConnectionHandler.java:160)
        at 
org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.  
java:338)
        at java.lang.Thread.run(Thread.java:479)
--------------------------------------------------------------------  
-------------------------------------------
SOURCE CODE from the 3.1 release ContextManager.java (handleError)
This includes the changes I made to get it to go to my own error page, 
which now works OK.
--------------------------------------------------------------------  
-------------------------------------------
	// Try a normal "error page"
	if( errorServlet==null && path != null ) {
	    try {
		RequestDispatcher rd = ctx.getRequestDispatcher(path);
		// reset the response, keeping the status code if necessary
		//res.reset(); // KL: THROWS IllegalStateException if res committed!
                if (code >= 400) {
                    res.setStatus(code);
                }
		// try a forward if possible, otherwise an include
		if (res.isBufferCommitted()) {
		    rd.include(req.getFacade(), res.getFacade());
                }
		else {
                            res.reset(); // Moved here from above: KL 
10may2000
		    rd.forward(req.getFacade(), res.getFacade());
                }
		return ;
	    } catch( Throwable t1 ) {
		ctx.log(" Error in custom error handler " + t1 );
		// nothing - we'll call DefaultErrorPage
                        // Added by KLease 10may2000 to avoid NPE below 
(errorServlet is null!)
	            req.setAttribute( "tomcat.servlet.error.defaultHandler", 
"true");
	            errorServlet=ctx.getServletByName("tomcat.errorPage");
	    }
	}
--------------------------------------------------------------------  
-------------------------------------------

I hope this helps.

Best regards,
Karen
/* =====================================
Karen Lease
SPX Valley Forge Technical Information Services
SPX France SA
147 avenue Paul Doumer
92500 Rueil-Malmaision France
Tel.: +33 (0)14751-1751
Fax: +33 (0)14751-8714
eMail: klease@vftis.com

visit us on the web at http://www.vftis.com
======================================*/

Mime
View raw message