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

Session.move fails even if existing destination node is removed in the same session

    Details

    • Steps to Reproduce:
      Hide
      @Test
      public void testOverwritingMove() throws Exception {
          final Session session = repository.login();
      
          try {
              // add 2 nodes under a parent that doesn't allow SNS
              final Node root = session.getRootNode();
      
              final Node parent = root.addNode("parent", "nt:folder");
      
              parent.addNode("name1", "nt:folder");
              parent.addNode("name2", "nt:folder");
      
              session.save();
      
              assertTrue("Added node 1 exists", session.nodeExists("/parent/name1"));
              assertTrue("Added node 2 exists", session.nodeExists("/parent/name2"));
      
              // overwrite 2 with 1
              session.removeItem("/parent/name2");
              // or session.getNode("/parent/name2").remove()
      
              assertFalse("Added node 2 doest not exist after remove", session.nodeExists("/parent/name2"));
              assertTrue("Added node 1 still exists", session.nodeExists("/parent/name1"));
      
              session.move("/parent/name1", "/parent/name2"); // <-- BUG: ItemExistsException thrown
      
              session.save();
      
          } finally {
              session.logout();
          }
      }
      
      Show
      @Test public void testOverwritingMove() throws Exception { final Session session = repository.login(); try { // add 2 nodes under a parent that doesn't allow SNS final Node root = session.getRootNode(); final Node parent = root.addNode( "parent" , "nt:folder" ); parent.addNode( "name1" , "nt:folder" ); parent.addNode( "name2" , "nt:folder" ); session.save(); assertTrue( "Added node 1 exists" , session.nodeExists( "/parent/name1" )); assertTrue( "Added node 2 exists" , session.nodeExists( "/parent/name2" )); // overwrite 2 with 1 session.removeItem( "/parent/name2" ); // or session.getNode( "/parent/name2" ).remove() assertFalse( "Added node 2 doest not exist after remove" , session.nodeExists( "/parent/name2" )); assertTrue( "Added node 1 still exists" , session.nodeExists( "/parent/name1" )); session.move( "/parent/name1" , "/parent/name2" ); // <-- BUG: ItemExistsException thrown session.save(); } finally { session.logout(); } }
    • Workaround Description:
      Hide

      Perform a Session.save() after Session.removeItem(destPath), and then do the Session.move after the save.

      (But this means it is not possible to perform a move with overwrite in one session)

      Show
      Perform a Session.save() after Session.removeItem(destPath) , and then do the Session.move after the save. (But this means it is not possible to perform a move with overwrite in one session)

      Description

      When trying to use Session.move(srcPath, destPath) when destPath exists, we must remove the node in destPath first. However, even after performing a Session.removeItem(destPath), Session.move still fails with the following exception:

      javax.jcr.ItemExistsException: A node definition that allows same name siblings could not be found for the node "/parent/name2[2]" in workspace "default"
      	at org.modeshape.jcr.AbstractJcrNode.validateChildNodeDefinition(AbstractJcrNode.java:1323)
      	at org.modeshape.jcr.JcrSession.move(JcrSession.java:1037)
      

      The problem only occurs if the parent node does not allow same name siblings.

      This effectively means it is not possible to implement behaviour to move and overwrite the destination node within one session.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                hchiorean Horia Chiorean
                Reporter:
                herculeszeus Hercules Zeus
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: