Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2457

NullPointerException when copying a locked node

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.3.0.Final
    • 4.2.0.Final
    • Server
    • None

    Description

      I am trying to copy a locked node using session.getWorkspace().copy(). From the documentation of copy, it is stated that:

      * @throws LockException                if a lock prevents the copy.
      

      It is not entirely clear to me what that means, but looking into the code for copy, I have deduced that you need to add the lock token (to the lock manager) of the node you wish to copy.

      Not doing this, results in a NullPointerException (and not a LockException) because the token is not there:

      Caused by: java.lang.NullPointerException
              at java.util.concurrent.ConcurrentHashMap.hash(ConcurrentHashMap.java:333) [rt.jar:1.7.0_65]
              at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:1016) [rt.jar:1.7.0_65]
              at java.util.Collections$SetFromMap.contains(Collections.java:3901) [rt.jar:1.7.0_65]
              at org.modeshape.jcr.JcrLockManager.hasLockToken(JcrLockManager.java:56) [modeshape-jcr-4.2.0.Final.jar:4.2.0.Final]
              at org.modeshape.jcr.JcrWorkspace.copy(JcrWorkspace.java:192) [modeshape-jcr-4.2.0.Final.jar:4.2.0.Final]
              at org.modeshape.jcr.JcrWorkspace.copy(JcrWorkspace.java:121) [modeshape-jcr-4.2.0.Final.jar:4.2.0.Final]
      

      Adding the token still results in a NullPointerException and I believe it is because of this code in the copy method:

         /*
          * Find the source node and check if it is locked
          */
          JcrSession sourceSession = session.spawnSession(srcWorkspace, true);
          AbstractJcrNode sourceNode = sourceSession.node(srcPath);
          if (session.lockManager().isLocked(sourceNode) && !session.lockManager().hasLockToken(sourceNode.getLock().getLockToken())) {
            throw new LockException(srcAbsPath);
          }
      

      The session.lockManager() has indeed the lock token. But sourceNode.getLock().getLockToken() is still null since its lock manager is associated to the spawned session (sourceSession).

      So maybe the problem is that lock tokens in the lock manager of a spawned session are not inherited from the lock manager of the session it was spawned from?

      Attachments

        Activity

          People

            hchiorean Horia Chiorean (Inactive)
            jacobilsoe_jira Jacob Ilsø (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: