javaserverfaces
  1. javaserverfaces
  2. JAVASERVERFACES-3265

NavigationHandler initialization is not thread-safe

    Details

      Description

      Running a stress test on my application with a large number of concurrent clients, I'm getting the following exception:

      Caused by: java.lang.NullPointerException
      	at com.sun.faces.application.NavigationHandlerImpl$NavigationInfo.access$000(NavigationHandlerImpl.java:1364) [jsf-impl-2.2.5-jbossorg-3.jar:]
      	at com.sun.faces.application.NavigationHandlerImpl.getNavigationMap(NavigationHandlerImpl.java:296) [jsf-impl-2.2.5-jbossorg-3.jar:]
      	at com.sun.faces.application.NavigationHandlerImpl.getViewId(NavigationHandlerImpl.java:478) [jsf-impl-2.2.5-jbossorg-3.jar:]
      	at com.sun.faces.application.NavigationHandlerImpl.getNavigationCase(NavigationHandlerImpl.java:149) [jsf-impl-2.2.5-jbossorg-3.jar:]
      	at com.sun.faces.application.NavigationHandlerImpl.getNavigationCase(NavigationHandlerImpl.java:140) [jsf-impl-2.2.5-jbossorg-3.jar:]
      

      This exception no longer occurs when the application has been warmed up by running a single request before going parallel.

      The root cause appears to be in com.sun.faces.application.NavigationHandlerImpl:

          private void createNavigationMaps() {
              if (null == navigationMaps) {
                  NavigationMap result = null;
                  NavigationInfo info = null;
                  navigationMaps = new ConcurrentHashMap<String, NavigationInfo>();
                  result = new NavigationMap();
                  info = new NavigationInfo();
                  info.ruleSet = result;
                  navigationMaps.put(ROOT_NAVIGATION_MAP_ID, info);
              }
          }
      

      The member this.navigationMaps is set before ROOT_NAVIGATION_MAP_ID is put into the map, so another thread may get null from navigationMap.get(ROOT_NAVIGATION_MAP_ID) in method getNavigationMap().

        Activity

        Hide
        Manfred Riem added a comment -

        Do you have a suggestion on how to fix this? Thanks!

        Show
        Manfred Riem added a comment - Do you have a suggestion on how to fix this? Thanks!
        Hide
        Harald Wellmann added a comment -

        I'd try this:

        
        private void createNavigationMaps() {
                if (null == navigationMaps) {
                    Map<String, NavigationInfo> maps = new ConcurrentHashMap<String, NavigationInfo>();
                    NavigationMap result = new NavigationMap();
                    NavigationInfo info = new NavigationInfo();
                    info.ruleSet = result;
                    maps.put(ROOT_NAVIGATION_MAP_ID, info);
                    this.navigationMaps = maps;
                }
            }
        
        Show
        Harald Wellmann added a comment - I'd try this: private void createNavigationMaps() { if ( null == navigationMaps) { Map< String , NavigationInfo> maps = new ConcurrentHashMap< String , NavigationInfo>(); NavigationMap result = new NavigationMap(); NavigationInfo info = new NavigationInfo(); info.ruleSet = result; maps.put(ROOT_NAVIGATION_MAP_ID, info); this .navigationMaps = maps; } }
        Hide
        Manfred Riem added a comment -

        Applied to 2.2 branch,

        svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-3265, reorder statements so createNavigationMaps becomes thread-safe."
        Sending jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java
        Transmitting file data .
        Committed revision 13257.

        Show
        Manfred Riem added a comment - Applied to 2.2 branch, svn commit -m "Fixes https://java.net/jira/browse/JAVASERVERFACES-3265 , reorder statements so createNavigationMaps becomes thread-safe." Sending jsf-ri/src/main/java/com/sun/faces/application/NavigationHandlerImpl.java Transmitting file data . Committed revision 13257.

          People

          • Assignee:
            Manfred Riem
            Reporter:
            Harald Wellmann
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: