Melloware created MYFACES-4786:
----------------------------------

             Summary: NPE "id is null" in NavigationHandlerImpl when a 
null-outcome navigation case uses <redirect/>
                 Key: MYFACES-4786
                 URL: https://issues.apache.org/jira/browse/MYFACES-4786
             Project: MyFaces Core
          Issue Type: Bug
          Components: General
    Affects Versions: 4.1.4, 4.0.4, 5.0.0
            Reporter: Melloware


The action method returns void, so the outcome is null. The navigation case 
matches on <from-action> and <if> only, and it includes <redirect/>. MyFaces 
then throws a NullPointerException instead of navigating.

The spec allows a null outcome to match a navigation case that has no 
<from-outcome> and does have an <if>. MyFaces matches the case correctly (see 
NavigationHandlerImpl.getNavigationCaseFromAction), but the redirect branch of 
handleNavigation calls calculateTargetFlow() with the null outcome. That call 
reaches FlowHandlerImpl.getFlow(context, "", null), which fails 
Assert.notNull(id, "id").

The same application works on Mojarra (WildFly).

Page:
{code:xml}
<h:commandButton id="btnNewPosting" value="New" 
action="#{postingsController.newPosting()}" />
{code}

Bean:
{code:java}
public void newPosting() { ... }
{code}

faces-config.xml:
{code:xml}
<navigation-rule>
    <from-view-id>/pages/secure/dashboard.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{postingsController.newPosting()}</from-action>
        <if>#{postingsController != null}</if>
        <to-view-id>/pages/secure/postingEditor.xhtml</to-view-id>
        <redirect />
    </navigation-case>
</navigation-rule>
{code}

Stack trace:
{noformat}
java.lang.NullPointerException: id is null.
    at org.apache.myfaces.core.api.shared.lang.Assert.notNull(Assert.java:35)
    at org.apache.myfaces.flow.FlowHandlerImpl.getFlow(FlowHandlerImpl.java:77)
    at 
org.apache.myfaces.application.NavigationHandlerImpl.calculateTargetFlow(NavigationHandlerImpl.java:513)
    at 
org.apache.myfaces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:173)
    at 
org.apache.myfaces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:117)
    at 
org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:122)
{noformat}

Expected: The navigation case matches and the browser is redirected to 
/pages/secure/postingEditor.xhtml.

Actual: NPE "id is null".

Workarounds: Return an explicit outcome from the action and match it with 
<from-outcome>, or remove <redirect/>.

Proposed fix: calculateTargetFlow() should return null when outcome is null, 
because a null outcome can never name a flow. Every other flow lookup in 
NavigationHandlerImpl already checks outcome != null (for example 
getNavigationCommand). The redirect path in handleNavigation is the only one 
that doesn't.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to