users@glassfish.java.net

Re: Exception handling, sun 8.1

From: Shing Wai Chan <Shing-Wai.Chan_at_Sun.COM>
Date: Thu, 25 Jun 2009 18:37:56 -0700

I have identified the problem and file issue
https://glassfish.dev.java.net/issues/show_bug.cgi?id=8591*
*
The description is as follows:
The following issue is posted for 8.1 and is also happens in v3.
Case A: If we have the following error-page map in web.xml,
  <error-page>
      <exception-type>java.lang.NoClassDefFoundError</exception-type>
      <location>noclass.jsp</location>
  </error-page>
then it works fine.

Case B: If we have the following in web.xml,
  <error-page>
      <exception-type>java.lang.NoClassDefFoundError</exception-type>
      <location>noclass.jsp</location>
  </error-page>
    <error-page>
      <exception-type>java.lang.Exception</exception-type>
      <location>catchall.jsp</location>
  </error-page>
then it seems that we always use the catchall.jsp
-----

The following is my analysis:
In StandardHostValve.java, we have
        Throwable realError = throwable;
        if (realError instanceof ServletException) {
            realError = ((ServletException) realError).getRootCause();
            if (realError == null) {
                realError = throwable;
            }
        }

        ErrorPage errorPage = findErrorPage(context, throwable);
        if ((errorPage == null) && (realError != throwable)) {
            errorPage = findErrorPage(context, realError);
        }

This means we try to find the error page for the given exception or its
super class first.
If it fails, the we find the one for the root cause.
So far, this is ok.

In the generated code of a jsp, we have the following:
   } catch (Throwable t) {
     if (!(t instanceof SkipPageException)){
       out = _jspx_out;
       if (out != null && out.getBufferSize() != 0)
         out.clearBuffer();
       if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
       else throw new ServletException(t);
     }
In JspServlet.java, we have
        try {
            boolean precompile = preCompile(request);
            serviceJspFile(request, response, jspUri, null, precompile);
        } catch (RuntimeException e) {
            // STARTS S1AS
            incrementErrorCount();
            // END S1AS
            throw e;
        } catch (ServletException e) {
            // STARTS S1AS
            incrementErrorCount();
            // END S1AS
            throw e;
        } catch (IOException e) {
            // STARTS S1AS
            incrementErrorCount();
            // END S1AS
            throw e;
        } catch (Throwable e) {
            // STARTS S1AS
            incrementErrorCount();
            // END S1AS
            throw new ServletException(e);
        }

So, if we have the NoClassDefFoundError, then it will be wrapped as
ServletException.
In Case A, there is no error page match for ServletException or its
super class. So, we will look at the cause exception. Hence it is ok.
In Case B, there is no error page match for ServletException. But it
matches for the super class Exception. Hence, it picks up the wrong
error page.

The issue that once should wrap any unchecked exception in generated
code and JspServlet.java.

Shing Wai Chan

Shing Wai Chan wrote:
> We see the same issue in GlassFish v3. We are looking at it now.
> Thanks for finding this issue.
> Shing Wai Chan
>
> glassfish_at_javadesktop.org wrote:
>> Hi All,
>> I have an application deployed that uses servlets, struts
>> and tiles to sun application server 8.1. I'm fairly new to all of
>> these, however I am attempting to write error catching in the
>> web.xml. If I have this:
>>
>> <error-page>
>> <exception-type>java.lang.NoClassDefFoundError</exception-type>
>> <location>/WEB-INF/pages/noclass.jsp</location>
>> </error-page>
>>
>> everything works fine and any noclassdeffounderrors are directed to
>> that page. If I also add a 'catch all' exception however to a
>> different page:
>>
>> <error-page>
>> <exception-type>java.lang.NoClassDefFoundError</exception-type>
>> <location>/WEB-INF/pages/noclass.jsp</location>
>> </error-page>
>> <error-page>
>> <exception-type>java.lang.Exception</exception-type>
>> <location>/WEB-INF/pages/catchall.jsp</location>
>> </error-page>
>>
>> then the second entry (java.lang.Exception) seems to take priority.
>> re-ordering these two in the web.xml doesn't seem to help. Is this a
>> bug in the application server or am I doing something wrong?
>> [Message sent by forum member 'mj3' (mj3)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=352871
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>