Details
Description
XHTML file:
<p:commandButton id="saveAndGo"
value="Save and Go"
action="#
"
ajax="false">
</p:commandButton>
Backing Bean method:
public String saveAction()
throws Exception
Invoking the command button produces the following stack trace, causing part of the next page to terminate rendering:
java.lang.NullPointerException
at java.io.Writer.write(Writer.java:140)
at org.mortbay.jetty.NCSARequestLog.log(NCSARequestLog.java:319)
at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:51)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:211)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
The section of jetty code that throws the NullPointerException is as follows (offending line highlighted):
if (_logCookies)
{
Cookie[] cookies = request.getCookies();
if (cookies == null || cookies.length == 0)
_writer.write(" -");
else
{
_writer.write(" \"");
for (int i = 0; i < cookies.length; i++)
_writer.write("\"");
}
}
Caused because the cookie oam.Flash.REDIRECT has a null value.
Looking at the source code for Myfaces Core - org.apache.myfaces.shared.context.flash.FlashImpl, the function _restoreRedirectValue has the following code which is used to remove the cookie:
if (cookie != null)
{ // the cookie exists means there was a redirect, regardless of the value externalContext.getRequestMap().put( FLASH_PREVIOUS_REQUEST_REDIRECT, Boolean.TRUE); // A redirect happened, so it is safe to remove the cookie, setting // the maxAge to 0 seconds. The effect is we passed FLASH_REDIRECT param // to this request object cookie.setMaxAge(0); cookie.setPath(_getCookiePath(externalContext)); cookie.setValue(null); httpResponse.addCookie(cookie); }My understanding is that a cookie can be removed by setMaxAge(0). Hence the setValue(null) is redundant. Removing this should fix the issue.