javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-2610

Possible NPE in StateContext.startTrackViewModifications

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.14
    • Fix Version/s: 2.1.16, 2.2.0-m07
    • Component/s: context
    • Labels:
      None

      Description

      It is currently possible for com.sun.faces.context.StateContext.startTrackViewModifications() to throw a NullPointerException when root is null. This is currently very unlikely to happen when using standard JSF but has been triggered from Spring Web Flow (see https://jira.springsource.org/browse/SWF-1571).

      One option might be to include a null check for root in the initial if statement:

      if (modListener == null && root != null) {
          modListener = new AddRemoveListener(ctx);
          root.subscribeToViewEvent(PostAddToViewEvent.class, modListener);
          // ...
      

        Activity

        Hide
        Manfred Riem added a comment -

        Can you please attach an example application (with sources) that triggers the problem?

        Show
        Manfred Riem added a comment - Can you please attach an example application (with sources) that triggers the problem?
        Hide
        pwebb added a comment -

        Hi Manfred,

        Unfortunately it is not possible to recreate the issue using JSF alone. However, the Spring Web Flow sample application [1] will trigger the problem on Web Flow 2.3 if you set javax.faces.PARTIAL_STATE_SAVING=false in the web.xml.

        The bug is only triggered because of the somewhat unique way that Web Flow deals with state management (see the initial comment in [2]). I have changed the way that Web Flow 2.4 deals with creating and restoring views so that it no longer triggers this issue but you still might want to consider if it is possible to pass a null root into startTrackViewModifications though some other code path.

        Cheers,
        Phil.

        [1] https://github.com/SpringSource/spring-webflow-samples/tree/master/booking-faces
        [2] https://jira.springsource.org/browse/SWF-1571

        Show
        pwebb added a comment - Hi Manfred, Unfortunately it is not possible to recreate the issue using JSF alone. However, the Spring Web Flow sample application [1] will trigger the problem on Web Flow 2.3 if you set javax.faces.PARTIAL_STATE_SAVING=false in the web.xml. The bug is only triggered because of the somewhat unique way that Web Flow deals with state management (see the initial comment in [2] ). I have changed the way that Web Flow 2.4 deals with creating and restoring views so that it no longer triggers this issue but you still might want to consider if it is possible to pass a null root into startTrackViewModifications though some other code path. Cheers, Phil. [1] https://github.com/SpringSource/spring-webflow-samples/tree/master/booking-faces [2] https://jira.springsource.org/browse/SWF-1571
        Hide
        Manfred Riem added a comment -

        Hi Phil,

        As far as I understand the spec, section 2.2.1 Restore View, correctly that piece of code should be safe to assume the UIViewRoot is populated by the time it is called. I could be wrong and if so please point it out so I can take the appropriate action. For now I will add print out a warning in the server log if it does get a null UIViewRoot.

        Thanks,
        Manfred

        Show
        Manfred Riem added a comment - Hi Phil, As far as I understand the spec, section 2.2.1 Restore View, correctly that piece of code should be safe to assume the UIViewRoot is populated by the time it is called. I could be wrong and if so please point it out so I can take the appropriate action. For now I will add print out a warning in the server log if it does get a null UIViewRoot. Thanks, Manfred
        Hide
        pwebb added a comment -

        Reading the spec again I think you are correct. Unfortunately Web Flow 2.3 did not detect when to call restoreView and when to call createView. We have a fix for Web Flow 2.4 so please feel free to close the issue.

        Thanks.

        Show
        pwebb added a comment - Reading the spec again I think you are correct. Unfortunately Web Flow 2.3 did not detect when to call restoreView and when to call createView . We have a fix for Web Flow 2.4 so please feel free to close the issue. Thanks.
        Hide
        Manfred Riem added a comment -

        Applied to 2.1 branch,

        svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2610, Added some logic to show the caller UIViewRoot is null where it should not be."
        Sending jsf-ri\src\main\java\com\sun\faces\context\StateContext.java
        Transmitting file data .
        Committed revision 11024.

        Show
        Manfred Riem added a comment - Applied to 2.1 branch, svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2610 , Added some logic to show the caller UIViewRoot is null where it should not be." Sending jsf-ri\src\main\java\com\sun\faces\context\StateContext.java Transmitting file data . Committed revision 11024.
        Hide
        Manfred Riem added a comment -

        Applied to 2.2 trunk,

        svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2610, Added some logic to show the caller UIViewRoot is null where it should not be."
        Sending jsf-ri\src\main\java\com\sun\faces\context\StateContext.java
        Transmitting file data .
        Committed revision 11025.

        Show
        Manfred Riem added a comment - Applied to 2.2 trunk, svn commit -m "Fixes http://java.net/jira/browse/JAVASERVERFACES-2610 , Added some logic to show the caller UIViewRoot is null where it should not be." Sending jsf-ri\src\main\java\com\sun\faces\context\StateContext.java Transmitting file data . Committed revision 11025.

          People

          • Assignee:
            Manfred Riem
            Reporter:
            pwebb
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: