You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nadav Katz <na...@oracle.com> on 2011/09/11 11:11:18 UTC

JSP Exception object arriving null at error handler

Hi,

I seem to be having a problem with the exception object attribute arriving null at the error handeling jsp. 

Since I encountered this error in production, I recreated on a small project.

This is the web.xml error page entry: 

<error-page>

                                <error-code>404</error-code>

                                <location>/notFoundErrorPage.jsp</location>

</error-page>

 

This is notFoundError.jsp:

<%@ page isErrorPage="true" %>

<%@ page isELIgnored="false"%>

 

<%

        if(exception != null)

        {

                System.out.println("Exception is not Null, it's " + exception.toString());

        }

                  else

                  {

                                System.out.println("Exception is Null!!");

                  }

%>

 

When I try to invoke a non-existing page, notFoundError.jsp is invoked, but the exception is null. I looked up the stack at ApplicationDisptacher.forward, and the request attributes are as follows:

 

[null, null, javax.servlet.error.message=/testing/nonExistantPage.jsp, null, null, null, null, javax.servlet.error.status_code=404, javax.servlet.error.servlet_name=jsp, null, null, null, javax.servlet.error.request_uri=/testing/nonExistantPage.jsp, null, null, null]

 

As you can see the exception is null…

What am I doing wrong? 

Thanks,

Nadav

RE: JSP Exception object arriving null at error handler

Posted by Nadav Katz <na...@oracle.com>.
Hello Chuck, thanks for your answer.
I have read the servlet spec, I don't remember coming across anything other than SRV 9.9 which relates, please direct me where to look if I'm wrong.
Also, I don't think I agree with you, for three reasons:
1. If I insert code in my jsp accessing a javascript file (for instance), but get the path wrong, don't you think it's an exception in the same way as a FileNotFoundException is an exception?
2.There is no difference from a developers point of view in the handling of 404 errors from any other types. When I declare an error page and map it to 404 status code, it's the exact same process as for any other code. There is no specific specification in SRV.9.9 that declares this type of error as different from the rest, and having generic logging code for all of them is (IMHO) the most logical conclusion from the information at hand.
3. My NPE wasn't at all trivial. It took me half a day + posting in the Tomcat users mailing list to find the answer. From looking online, I'm not the first to encounter it, but it appears like I'm one of the first to actually have it answered. That in itself suggests that the "404 is not an exception" logic is at the very least not ubiquitous, which suggests the need for at least better documentation
In any case, since I am going to change the code, are there any other types of errors that are not considered exceptions that I should take into consideration? 
Thanks,
Nadav 

-----Original Message-----
From: Caldarale, Charles R [mailto:Chuck.Caldarale@unisys.com] 
Sent: Sunday, September 11, 2011 5:26 PM
To: Tomcat Users List
Subject: RE: JSP Exception object arriving null at error handler

> From: Nadav Katz [mailto:nadav.katz@oracle.com] 
> Subject: RE: JSP Exception object arriving null at error handler

> Is there anywhere where I can find documentation for this?

Read the servlet spec.

> I'm asking because I came across this behavior by chance when I got 
> a NullPointerException in logging code calling exception.getMessage().

Which means your logging code contains invalid assumptions.

> Is it possible that I will come across this with other types of 
> exceptions?

You're missing the point: a 404 status is *not* an exception.

> Is my logging code unusable?

Not necessarily unusable, but certainly broken.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSP Exception object arriving null at error handler

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Nadav Katz [mailto:nadav.katz@oracle.com] 
> Subject: RE: JSP Exception object arriving null at error handler

> Is there anywhere where I can find documentation for this?

Read the servlet spec.

> I'm asking because I came across this behavior by chance when I got 
> a NullPointerException in logging code calling exception.getMessage().

Which means your logging code contains invalid assumptions.

> Is it possible that I will come across this with other types of 
> exceptions?

You're missing the point: a 404 status is *not* an exception.

> Is my logging code unusable?

Not necessarily unusable, but certainly broken.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: JSP Exception object arriving null at error handler

Posted by Nadav Katz <na...@oracle.com>.
Hi Bob, 
Thanks for the quick reply. Is there anywhere where I can find documentation for this? I'm asking because I came across this behavior by chance when I got a NullPointerException in logging code calling exception.getMessage().
Is it possible that I will come across this with other types of exceptions? Is my logging code unusable?
Thanks,
Nadav
-----Original Message-----
From: Bob Hall [mailto:rfhall3@yahoo.com] 
Sent: Sunday, September 11, 2011 12:54 PM
To: Tomcat Users List
Subject: Re: JSP Exception object arriving null at error handler





________________________________
From: Nadav Katz <na...@oracle.com>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Sunday, September 11, 2011 2:11 AM
Subject: JSP Exception object arriving null at error handler

Hi,

I seem to be having a problem with the exception object attribute arriving null at the error handeling jsp. 

Since I encountered this error in production, I recreated on a small project.

This is the web.xml error page entry: 

<error-page>

                                <error-code>404</error-code>

                                <location>/notFoundErrorPage.jsp</location>

</error-page>

 

This is notFoundError.jsp:

<%@ page isErrorPage="true" %>

<%@ page isELIgnored="false"%>

 

<%

        if(exception != null)

        {

                System.out.println("Exception is not Null, it's " + exception.toString());

        }

                  else

                  {

                                System.out.println("Exception is Null!!");

                  }

%>

What am I doing wrong? 

====

Nadav,

There is no Exception in this case.

This example should work for you _and_ allow you to display the resource that was not found:

http://stackoverflow.com/questions/4948275/get-url-of-page-requested-that-caused-a-404

- Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: JSP Exception object arriving null at error handler

Posted by Bob Hall <rf...@yahoo.com>.



________________________________
From: Nadav Katz <na...@oracle.com>
To: Tomcat Users List <us...@tomcat.apache.org>
Sent: Sunday, September 11, 2011 2:11 AM
Subject: JSP Exception object arriving null at error handler

Hi,

I seem to be having a problem with the exception object attribute arriving null at the error handeling jsp. 

Since I encountered this error in production, I recreated on a small project.

This is the web.xml error page entry: 

<error-page>

                                <error-code>404</error-code>

                                <location>/notFoundErrorPage.jsp</location>

</error-page>

 

This is notFoundError.jsp:

<%@ page isErrorPage="true" %>

<%@ page isELIgnored="false"%>

 

<%

        if(exception != null)

        {

                System.out.println("Exception is not Null, it's " + exception.toString());

        }

                  else

                  {

                                System.out.println("Exception is Null!!");

                  }

%>

What am I doing wrong? 

====

Nadav,

There is no Exception in this case.

This example should work for you _and_ allow you to display the resource that was not found:

http://stackoverflow.com/questions/4948275/get-url-of-page-requested-that-caused-a-404

- Bob