diff --git a/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java b/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java index c3ba156d91..35bd82871f 100755 --- a/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java +++ b/impl/src/main/java/org/apache/myfaces/application/NavigationHandlerImpl.java @@ -492,6 +492,11 @@ public NavigationCase getNavigationCommandFromGlobalNavigationCases( private Flow calculateTargetFlow(FacesContext facesContext, String outcome, FlowHandler flowHandler, List activeFlows, String toFlowDocumentId) { + // MYFACES-4786: a null outcome (e.g. void action method) can never identify a flow + if (outcome == null) + { + return null; + } Flow targetFlow = null; if (toFlowDocumentId != null) { diff --git a/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java b/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java index 2ab90ec4af..34bb04e771 100644 --- a/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java +++ b/impl/src/test/java/org/apache/myfaces/application/NavigationHandlerImplTest.java @@ -34,6 +34,7 @@ import org.apache.myfaces.config.RuntimeConfig; import org.apache.myfaces.config.element.NavigationRule; import org.apache.myfaces.config.impl.FacesConfigUnmarshallerImpl; +import org.apache.myfaces.flow.FlowHandlerImpl; import org.apache.myfaces.test.base.junit.AbstractJsfTestCase; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; @@ -698,5 +699,33 @@ public void testIfDoNotMatchWhenOutcomeNull() throws Exception Assertions.assertEquals("/b.jsp", nc.getToViewId(facesContext)); } + + /** + * MYFACES-4786: a void action method yields a null outcome. A navigation case with + * from-action + if (and no from-outcome) matches it, and when that case is a redirect + * the target flow calculation must not fail with "id is null". + */ + @Test + public void testHandleNullOutcomeWithFromActionIfAndRedirect() throws Exception + { + loadTextFacesConfig("null-outcome-redirect-rules-config.xml"); + + // use the real FlowHandler, the mock one does not validate its arguments + application.setFlowHandler(new FlowHandlerImpl()); + + externalContext.getRequestMap().put("test", new TestBean()); + + facesContext.getViewRoot().setViewId("/a.jsp"); + + final NavigationHandlerImpl nh = new NavigationHandlerImpl(); + + NavigationCase nc = nh.getNavigationCase(facesContext, "#{test.go}", null); + Assertions.assertNotNull(nc); + Assertions.assertEquals("/b.jsp", nc.getToViewId(facesContext)); + Assertions.assertTrue(nc.isRedirect()); + + Assertions.assertDoesNotThrow(() -> nh.handleNavigation(facesContext, "#{test.go}", null)); + Assertions.assertTrue(facesContext.getResponseComplete()); + } } diff --git a/impl/src/test/resources/org/apache/myfaces/application/null-outcome-redirect-rules-config.xml b/impl/src/test/resources/org/apache/myfaces/application/null-outcome-redirect-rules-config.xml new file mode 100644 index 0000000000..5379f131da --- /dev/null +++ b/impl/src/test/resources/org/apache/myfaces/application/null-outcome-redirect-rules-config.xml @@ -0,0 +1,30 @@ + + + + + /a.jsp + + #{test.go} + #{test.true} + /b.jsp + + + +