title: 404 on FacesServlet causes infinite loop with java.lang.NullPointerException at org.apache.myfaces.shared_impl.context.flash.FlashImpl.isKeepMessages
body: <p>In WebSphere 8.5, accessing <code>/myapp</code>, <code>/myapp/</code>, <code>/myapp/nosuchpage</code> and <code>/myapp/faces/nosuchpage</code> will procude a 404, which is fine. But <code>/myapp/faces</code> and <code>/myapp/faces/</code> causes instead of 404 an infinite loop with a NPE on MyFaces Flash scope as seen in the log.</p>
  
  <pre class="lang-java prettyprint-override"><code>[3/6/15 16:58:03:391 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] phase=RESTORE_VIEW(1)
  [3/6/15 16:58:03:391 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] phase=RENDER_RESPONSE(6)
  [3/6/15 16:58:03:391 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] fc.viewRoot.viewId=/faces/ fc.application.viewHandler.actionURL=/jsfTest2/faces//faces/
  ... (repeats)
  [3/6/15 16:58:03:392 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] phase=RESTORE_VIEW(1)
  [3/6/15 16:58:03:392 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] phase=RENDER_RESPONSE(6)
  [3/6/15 16:58:03:392 CST] 000000f7 SystemOut     O [PhaseListener:beforePhase] fc.viewRoot.viewId=/faces/ fc.application.viewHandler.actionURL=/jsfTest2/faces//faces/
  [3/6/15 16:58:03:405 CST] 000000f7 ErrorPageWrit E   An exception occurred
                                   java.lang.NullPointerException
      at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:107)
      at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:186)
      at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:119)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1111)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1385)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:194)
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:367)
      at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:94)
      at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:66)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:240)
      ... (repeats)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1111)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3901)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
      at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1865)
  
  [3/6/15 16:58:03:429 CST] 000000f7 ServletWrappe E com.ibm.ws.webcontainer.servlet.ServletWrapper service SRVE0068E: An exception was thrown by one of the service methods of the servlet [Faces Servlet] in application [jsfTest2EAR]. Exception created : [java.lang.NullPointerException
      at org.apache.myfaces.shared_impl.context.flash.FlashImpl.isKeepMessages(FlashImpl.java:394)
      at org.apache.myfaces.shared_impl.context.flash.FlashImpl._saveMessages(FlashImpl.java:669)
      at org.apache.myfaces.shared_impl.context.flash.FlashImpl.doPostPhaseActions(FlashImpl.java:275)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:252)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1111)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:1385)
      at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:194)
      at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:367)
      at org.apache.myfaces.view.jsp.JspViewDeclarationLanguage.buildView(JspViewDeclarationLanguage.java:94)
      at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:66)
      at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:240)
      ... (repeats)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1230)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:779)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:478)
      at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1111)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3901)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:981)
      at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
      at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:200)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:463)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:530)
      at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:316)
      at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:88)
      at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:175)
      at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
      at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
      at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
      at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
      at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
      at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
      at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1865)
  ]
  [3/6/15 16:58:03:442 CST] 000000f7 LocalTranCoor E   WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
  ... (repeats)
  [3/6/15 16:58:04:523 CST] 000000f7 SRTServletRes W com.ibm.ws.webcontainer.srt.SRTServletResponse setStatus WARNING: Cannot set status. Response already committed.
  [3/6/15 16:58:04:523 CST] 000000f7 SRTServletRes W com.ibm.ws.webcontainer.srt.SRTServletResponse addHeader SRVE8094W: WARNING: Cannot set header. Response already committed.
  </code></pre>
  
  <p>Adding <code>&lt;error-page&gt;</code> for 404 does not help. No such looping is observed in WebSphere 6.1. Perhaps a bug in MyFaces bundled in WebSphere 8.5?</p>
  
  <p>This is my <code>web.xml</code>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"&gt;
  
      &lt;display-name&gt;jsfTest2&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
          &lt;param-value&gt;server&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.CONFIG_FILES&lt;/param-name&gt;
          &lt;param-value&gt;&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
          &lt;param-value&gt;.xhtml&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;com.ibm.ws.jsf.JSP_UPDATE_CHECK&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;com.ibm.ws.jsf.LOAD_FACES_CONFIG_AT_STARTUP&lt;/param-name&gt;
          &lt;param-value&gt;true&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;-1&lt;/load-on-startup&gt;
          &lt;enabled&gt;true&lt;/enabled&gt;
          &lt;async-supported&gt;false&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.faces&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/faces/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>