users@glassfish.java.net

Re: Obtaining LoginException

From: <Jan.Luehe_at_Sun.COM>
Date: Fri, 03 Aug 2007 08:52:29 -0700

Hi Joe,

Shevland, Joe wrote:

>>>very recently in GlassFish v2 (as of build 57).
>>>
>>>
>
>I'm still seeing the same NPE in build 57:
>
>[#|2007-08-03T16:34:39.671+1000|WARNING|sun-appserver9.1|org.apache.cata
>lina.authenticator.FormAuthenticator|_ThreadID=17;_ThreadName=httpSSLWor
>kerThread-8181-0
>;_RequestID=f2528be5-34eb-4753-84d4-e5a55360f5b1;|Unexpected error
>forwarding or redirecting to login page
>org.apache.jasper.JasperException: java.lang.NullPointerException
> at
>org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
>va:402)
> ...
> ...
>Caused by: java.lang.NullPointerException
> at org.apache.jsp.login.login_jsp._jspService(login_jsp.java:26)
>
>The offending code still being:
>
>
>response.setStatus(((Integer)request.getAttribute("javax.servlet.error.s
>tatus_code")).intValue());
>
>
>Just putting <%_at_page isErrorPage="true"%> is enough to trigger this in
>the form-error-page page,
>

See my earlier reply: The "javax.servlet.error.status_code"
request attribute is null in a <form-error-page> resource,
which means that if you set <%_at_page isErrorPage="true"%>
in your <form-error-page> resource, this line:

  
response.setStatus(((Integer)request.getAttribute("javax.servlet.error.status_code")).intValue());

which is automatically generated by the JSP compiler for any JSP that has
<%_at_page isErrorPage="true"%>, will result in the NPE you saw.

> although I've tried with and without -
>without, the NPE just occurs further down in the code when I try and do
>a System.out.println(pageContext.getErrorData()):
>
>

Same root cause, though.

javax.servlet.jsp.PageContext.getErrorData() is implemented as follows:


    public ErrorData getErrorData() {
        return new ErrorData(
            (Throwable)getRequest().getAttribute(
"javax.servlet.error.exception" ),
            ((Integer)getRequest().getAttribute(
                "javax.servlet.error.status_code" )).intValue(),
            (String)getRequest().getAttribute(
"javax.servlet.error.request_uri" ),
            (String)getRequest().getAttribute(
"javax.servlet.error.servlet_name" ) );
    }

Since the "javax.servlet.error.status_code" request attribute is null
in a <form-error-page> resource,

            ((Integer)getRequest().getAttribute(
                "javax.servlet.error.status_code" )).intValue(),

will cause the NPE.

The only recommendation I can give you is to not add
<%_at_page isErrorPage="true"%> to your <form-error-page> resource,
and to not try to retrieve the pagecontext's error data
(${pageContext.errorData}) from your <form-error-page> resource.

It would be nice if any of these error triggers could have been
flagged somehow, since they are not very intuitive at first glance.


Jan
 

>Caused by: java.lang.NullPointerException
> at
>javax.servlet.jsp.PageContext.getErrorData(PageContext.java:536)
> at
>org.apache.jsp.login.login_005ferror_jsp._jspService(login_005ferror_jsp
>..java:49)
>
>Cheers,
>Joe
>
>This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>