4 Replies Latest reply on Jan 18, 2012 2:31 PM by Randall Hauch

    ensureRequiredPrimaryTypesLoaded throwing NullPointerException on first access under Jetty

    KimJohn Quinn Newbie

      I am working on a "resource" controller using the latest Spring3 and JBoss Modeshape (pointing to a federated repository using the Filesystem connectors) to retrieve an asset.

      When I access any webpage, using the controller, it returns most of the images then throws a NullPointerException in the "getNode" call at various other ones...

      On my end, I am not doing anything special (my test cases work fine):

      1. Create/configure the engine (only once)
      2. Login and get a session
      3. Try to find the node
      4. Logout from the session

      The code pretty much looks like:

      session = createSession(); Node node = session.getNode(path); 

      After the first hit to the page (with errors), every hit after that works perfect and everything loads fine from then out.

      I am following this link Heavy Concurrency: A better way to manage JCR Sessions for the session creation/management.

      It appears as if I have multiple threads trying to configure the JcrNodeDefinition in Modeshape. If i mark the enureRequirePrimaryTypesLoaded() method as synchronized then I do not get the error ever.

      Anyone have any experience/suggestions with using Modeshape, concurrency, and session management?

      The stack trace is:

      java.lang.NullPointerException at org.modeshape.jcr.JcrNodeDefinition.ensureRequiredPrimaryTypesLoaded(JcrNodeDefinition.java:114) at org.modeshape.jcr.JcrNodeDefinition.allowsChildWithType(JcrNodeDefinition.java:275) at org.modeshape.jcr.RepositoryNodeTypeManager.findChildNodeDefinition(RepositoryNodeTypeManager.java:1142) at org.modeshape.jcr.JcrNodeTypeManager.findChildNodeDefinition(JcrNodeTypeManager.java:433) at org.modeshape.jcr.SessionCache$JcrNodeOperations.materialize(SessionCache.java:2711) at org.modeshape.graph.session.GraphSession$Node.load(GraphSession.java:1755) at org.modeshape.graph.session.GraphSession$Node.getPayload(GraphSession.java:3030) at org.modeshape.jcr.AbstractJcrNode.getNode(AbstractJcrNode.java:950) at org.modeshape.jcr.AbstractJcrNode.getNode(AbstractJcrNode.java:96) at com.acme.beans.contents.FileNodeAdapter.(FileNodeAdapter.java:26) at com.acme.web.views.ResourceController.getStream(ResourceController.java:77) at com.acme.web.views.ResourceController.handleResource(ResourceController.java:46)

        • 1. Re: ensureRequiredPrimaryTypesLoaded throwing NullPointerException on first access under Jetty
          Randall Hauch Master

          It does sound like there is a concurrency problem during initialization, but your stack trace confuses me. In particular, the first line:

          java.lang.NullPointerException at org.modeshape.jcr.JcrNodeDefinition.ensureRequiredPrimaryTypesLoaded(JcrNodeDefinition.java:114) at

          If you're using ModeShape 2.7.0.Final, then line 114 is a simple null reference check, which cannot result in a NullPointerException:

           

                    if (requiredPrimaryTypesByName != null) return;

           

          Also, the second line of the stack trace is also troubling, because JcrNodeDefinition line 275 is the terminating '}' of a method.

           

          Have you changed the source in any way, or are you running against a released version?

          • 2. Re: ensureRequiredPrimaryTypesLoaded throwing NullPointerException on first access under Jetty
            KimJohn Quinn Newbie

            I am using Modeshape 2.7.0 Final.

             

            Sorry, I was playing with the code to see if I could figure out what the problem is.  The exact stack trace returned back is:

             

            java.lang.NullPointerException

                      at org.modeshape.jcr.JcrNodeDefinition.ensureRequiredPrimaryTypesLoaded(JcrNodeDefinition.java:121)

                      at org.modeshape.jcr.JcrNodeDefinition.allowsChildWithType(JcrNodeDefinition.java:249)

                      at org.modeshape.jcr.RepositoryNodeTypeManager.findChildNodeDefinition(RepositoryNodeTypeManager.java:1142)

                      at org.modeshape.jcr.RepositoryNodeTypeManager.findChildNodeDefinition(RepositoryNodeTypeManager.java:1161)

                      at org.modeshape.jcr.JcrNodeTypeManager.findChildNodeDefinition(JcrNodeTypeManager.java:433)

                      at org.modeshape.jcr.SessionCache$JcrNodeOperations.materialize(SessionCache.java:2711)

                      at org.modeshape.graph.session.GraphSession.findNodeRelativeTo(GraphSession.java:535)

                      at org.modeshape.graph.session.GraphSession.findNodeWith(GraphSession.java:398)

                      at org.modeshape.graph.session.GraphSession.findNodeWith(GraphSession.java:381)

                      at org.modeshape.jcr.SessionCache.findNode(SessionCache.java:532)

                      at org.modeshape.jcr.SessionCache.findJcrNode(SessionCache.java:643)

                      at org.modeshape.jcr.JcrSession.getNode(JcrSession.java:838)

                      at org.modeshape.jcr.JcrSession.getNode(JcrSession.java:703)

                      at org.modeshape.jcr.JcrSession.getNode(JcrSession.java:96)

                      at com.acme.contents.ModeshapeManagerBean.findNode(ModeshapeManagerBean.java:67)

                      at com.acme.contents.ModeshapeManagerBean.findNode(ModeshapeManagerBean.java:50)

                      at com.acme.views.ResourceController.getStream(ResourceController.java:69)

                      at comacme.views.ResourceController.handleResource(ResourceController.java:46)

                      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                      at java.lang.reflect.Method.invoke(Method.java:597)

                      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)

                      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)

                      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)

                      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:6

            • 3. Re: ensureRequiredPrimaryTypesLoaded throwing NullPointerException on first access under Jetty
              Randall Hauch Master

              Okay, that makes much more sense, and is perfectly explained by the concurrent bug I found and described in MODE-1374. I have a fix that I'm currently in the process of testing. (The fix doesn't synchronize the whole 'ensureRequiredPrimaryTypesLoaded()' method, but rather synchronizes just one critical part of the method.) I'll likely merge it into the 'master' branch and '3.x' branch within the hour.

               

              Thanks for reporting the issue and doing the initial investigation yourself. That work saved us a great deal of time and effort, and allowed us to quickly identify the problem.

              • 4. Re: ensureRequiredPrimaryTypesLoaded throwing NullPointerException on first access under Jetty
                Randall Hauch Master

                The fix has been merged into the codebase and will be in all upcoming releases. Feel free to continue to use in the meantime change you suggested to add the 'synchronized' keyword to the 'ensureRequiredNodeTypesLoaded()' mehtod. You can also look at the details of our fix (which is a bit more subtle).

                 

                Again, thanks for reporting this!