dev@mojarra.java.net

NPE in NavigationHandlerImpl

From: Frank Würffel <frank_wuerffel_at_hotmail.com>
Date: Thu, 26 Jan 2012 17:19:15 +0100

Hi,

I had a NPE in NavigationHandlerImpl when I configure a Nav Case with redirect and the session has expired before the navigation takes place.
This is due to a missing check fo null in the methods:

clearViewMapIfNecessary and updateRenderTargets

I fixed this for me by creating my own NavigationHandler but it would be nice to have it fixed in the mojarra code if possible.

    /**
     * Calls <code>clear()</code> on the ViewMap (if available) if the view ID of the UIViewRoot differs from <code>newId</code>
     */
    private void clearViewMapIfNecessary(UIViewRoot root, String newId) {

        if (root != null && !root.getViewId().equals(newId)) {
            Map<String, Object> viewMap = root.getViewMap(false);
            if (viewMap != null) {
                viewMap.clear();
            }
        }

    }

    private void updateRenderTargets(FacesContext ctx, String newId) {

        if (ctx.getViewRoot() == null || !ctx.getViewRoot().getViewId().equals(newId)) {
            PartialViewContext pctx = ctx.getPartialViewContext();
            if (!pctx.isRenderAll()) {
                pctx.setRenderAll(true);
            }
        }

    }


Tks.

Frank