Feb 05
Tomcat 6.0.14 + JSTL 1.2_07 RI = *Boom* NullPointerException
I guess I’ve had a busy / buggy weekend noodling around with stuff. I ran into a [known] bug in the latest JSTL/JSF 1.2 Reference Implementation on Tomcat 6.0.14.
I was playing around with Spring MVC 2.5.1, and even the simplest JSP page gave me this:
java.lang.NullPointerException com.sun.faces.application.WebappLifecycleListener.syncSessionScopedBeans(WebappLifecycleListener.java:312) com.sun.faces.application.WebappLifecycleListener.requestDestroyed(WebappLifecycleListener.java:87) com.sun.faces.config.ConfigureListener.requestDestroyed(ConfigureListener.java:240) [snip]
This is interesting, because I wasn’t even using JSF!
It turns out that there’s a bug that is lightly documented in the JSTL/JSF 1.2_07 RI release notes:
There is a chance for an NPE in com.sun.faces.application.WebappLifecycleListener with some configurations (see issue 670). Take for example, installing JSF in a container such that JSF will be available to all web applications. The NPE will occur for an application that doesn’t have the FacesServlet defined within it’s web.xml.
The workaround for this issue is, within the global web.xml for the container (JBoss and Tomcat both have one) add either a FacesServlet definition (no mapping) or add the context init parameter, com.sun.faces.forceLoadConfiguration, with a value of true. NOTE: GlassFish is not affected by this issue.
This is also covered in the Mojarra bug database as bug 670, and the JBoss bug database as bug JBAS-5063.
There’s some discussion in this JBoss forum thread indicating how to solve for JBoss AS, which is a good start.
For Tomcat 6, you can add the following to context.xml:
<Parameter name="com.sun.faces.forceLoadConfiguration" value="true"/>One caveat here is if you’re running an Eclipse-based Tomcat instance. Eclipse-configured Tomcat doesn’t have an easily accessible context.xml. Instead, you’ll have to configure this in the global default webapp. Look in your Eclipse workspace for the server configuration (by default, Eclipse will put this in a top-level project called “Servers”).
In the web.xml you’ll find in there, add the following:
<context-param> <param-name>com.sun.faces.forceLoadConfiguration</param-name> <param-value>true</param-value> </context-param>
This should not be put in your web application’s web.xml!
Once you do this, you should not receive the NullPointerException upon first access to a JSP. It looks like this bug will be fixed in the next RI release of JSF/JSTL.

