webtier@glassfish.java.net

Re: [webtier] JSF/JSF2 Seemingly random NullPointerExceptionsinrequest.get/setAttribute() using Filters

From: <lincolnbaxter_at_gmail.com>
Date: Mon, 6 Apr 2009 23:15:17 +0000

6.0.18


Sent from my Verizon Wireless BlackBerry

-----Original Message-----
From: Ryan Lubke <Ryan.Lubke_at_Sun.COM>

Date: Mon, 06 Apr 2009 15:27:05
To: <webtier_at_glassfish.dev.java.net>
Subject: Re: [webtier] JSF/JSF2 Seemingly random NullPointerExceptions
 inrequest.get/setAttribute() using Filters

On 4/6/09 3:18 PM, lincolnbaxter_at_gmail.com wrote:
> Crud, this is probably a tomcat list question. This hasn't happened
> until recently though, and the only thing that's really changed is
> jsf2 versions
You can still share the version of Tomcat though, yes?
>
> Sent from my Verizon Wireless BlackBerry
>
> ------------------------------------------------------------------------
> *From*: Ryan Lubke
> *Date*: Mon, 06 Apr 2009 15:16:11 -0700
> *To*: <webtier_at_glassfish.dev.java.net>
> *Subject*: Re: [webtier] JSF/JSF2 Seemingly random
> NullPointerExceptions in request.get/setAttribute() using Filters
> On 4/6/09 3:04 PM, Lincoln Baxter, III wrote:
>> Hi Gurus,
>>
>> Got a question...
> Since it seems that this may be a container issue, what container are
> you using?
>>
>> I'm using PrettyFaces for JSF (trying to update it for JSF2,) and I
>> started getting some NullPointerExceptions that I don't feel like
>> were occurring before.
>>
>> Here are the steps that occur:
>>
>> 1. PrettyFaces intercepts all requests to the WebApp, it checks
>> against a configuration file to determine whether or not that request
>> should be forwarded to JSF.
>>
>> 2. PrettyFaces then constructs a FacesContext in order to do some
>> work with FacesMessages, :
>>
>> public FacesContext getFacesContext(final ServletRequest request,
>> final ServletResponse response)
>> {
>> FacesContext facesContext = FacesContext.getCurrentInstance();
>> if (facesContext != null)
>> {
>> return facesContext;
>> }
>>
>> FacesContextFactory contextFactory = (FacesContextFactory)
>> FactoryFinder
>> .getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
>> LifecycleFactory lifecycleFactory = (LifecycleFactory)
>> FactoryFinder
>> .getFactory(FactoryFinder.LIFECYCLE_FACTORY);
>> Lifecycle lifecycle =
>> lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
>>
>> ServletContext servletContext = ((HttpServletRequest)
>> request).getSession().getServletContext();
>> facesContext = contextFactory.getFacesContext(servletContext,
>> request, response, lifecycle);
>> InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);
>>
>> return facesContext;
>> }
>>
>> 3. PrettyFaces constructs a PrettyContext and PrettyConfig object,
>> and stores them using request.setAttribute()
>>
>> 4. PrettyFaces forwards to JSF (or not, if not applicable)
>>
>> It seems like these attributes are sometimes lost during the forward
>> to the JSF servlet. This must have something to do with threading and
>> forwards, but I can't seem to narrow it down. Any help would be
>> greatly appreciated.
>>
>> Sometimes the Exceptions occur even before the forward to JSF.
>>
>> Caused by: java.lang.NullPointerException
>> at
>> org.apache.catalina.connector.Request.setAttribute(Request.java:1424)
>> at
>> org.apache.catalina.connector.RequestFacade.setAttribute(RequestFacade.java:503)
>> at
>> javax.servlet.ServletRequestWrapper.setAttribute(ServletRequestWrapper.java:284)
>> at
>> com.ocpsoft.pretty.PrettyContext.setCurrentInstance(PrettyContext.java:93)
>> at
>> com.ocpsoft.pretty.PrettyContext.getCurrentInstance(PrettyContext.java:84)
>> at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:58)
>> at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>> at
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>> at
>> com.ocpsoft.socialpm.jsf.filter.DataSetupFilter.doFilter(DataSetupFilter.java:255)
>> at
>> org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
>> at
>> org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
>> at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>> at
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>> at
>> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
>> at
>> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
>> at
>> org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
>> at
>> org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
>> at
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
>>
>>
>> Where and how should I start trying to debug these random NPEs?
>>
>>
>> Thanks,
>> Lincoln
>>
>>
>>
>