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

The org.modeshape.jcr.JcrNode.getNodes(String) method returns an invalid iterator when the session is not saved yet

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Critical Critical
    • 3.3.0.Final
    • 3.1.3.Final, 3.2.0.Final
    • JCR
    • None
    • Hide

      You will find an example below that demonstrates the problem:

      public class TestModeShape extends org.modeshape.test.ModeShapeSingleUseTest {
      
          @Test
          public void testGetNodesMethod() throws Exception {
              Node jcrRootNode = ((Session) session).getRootNode();
              Node rootNode = jcrRootNode.addNode("mapSuperclassTest");
              Node newNode = rootNode.addNode("newNode");
              NodeIterator nodeIterator = rootNode.getNodes("myMap"); // Gets all child nodes that match 'myMap'
              assertTrue(nodeIterator.hasNext()); // It's not correct ! there should be an empty iterator !
              assertEquals(newNode.getName(), nodeIterator.nextNode().getName()); // The next node is 'newNode'
              session.save();
              nodeIterator = rootNode.getNodes("myMap");
              assertFalse(nodeIterator.hasNext()); // It's correct after saving
          }
      }
      

      ---------------------------------------------------------------------------

      You will find the unit test that is expected :

      public class TestModeShape extends org.modeshape.test.ModeShapeSingleUseTest {
      
          @Test
          public void testGetNodesMethod() throws Exception {
              Node jcrRootNode = ((Session) session).getRootNode();
              Node rootNode = jcrRootNode.addNode("mapSuperclassTest");
              Node newNode = rootNode.addNode("newNode");
              NodeIterator nodeIterator = rootNode.getNodes("myMap");
              assertFalse(nodeIterator.hasNext());
              session.save();
              nodeIterator = rootNode.getNodes("myMap");
              assertFalse(nodeIterator.hasNext());
          }
      }
      
      Show
      You will find an example below that demonstrates the problem: public class TestModeShape extends org.modeshape.test.ModeShapeSingleUseTest { @Test public void testGetNodesMethod() throws Exception { Node jcrRootNode = ((Session) session).getRootNode(); Node rootNode = jcrRootNode.addNode( "mapSuperclassTest" ); Node newNode = rootNode.addNode( "newNode" ); NodeIterator nodeIterator = rootNode.getNodes( "myMap" ); // Gets all child nodes that match 'myMap' assertTrue(nodeIterator.hasNext()); // It's not correct ! there should be an empty iterator ! assertEquals(newNode.getName(), nodeIterator.nextNode().getName()); // The next node is 'newNode' session.save(); nodeIterator = rootNode.getNodes( "myMap" ); assertFalse(nodeIterator.hasNext()); // It's correct after saving } } --------------------------------------------------------------------------- You will find the unit test that is expected : public class TestModeShape extends org.modeshape.test.ModeShapeSingleUseTest { @Test public void testGetNodesMethod() throws Exception { Node jcrRootNode = ((Session) session).getRootNode(); Node rootNode = jcrRootNode.addNode( "mapSuperclassTest" ); Node newNode = rootNode.addNode( "newNode" ); NodeIterator nodeIterator = rootNode.getNodes( "myMap" ); assertFalse(nodeIterator.hasNext()); session.save(); nodeIterator = rootNode.getNodes( "myMap" ); assertFalse(nodeIterator.hasNext()); } }

      It seems to me that there is a bug in the org.modeshape.jcr.JcrNode.getNodes(String) method when the session has not been saved yet.

      The method returns nodes that don't match the pattern as a parameter.

      I tested with Jackrabbit and I don't have this problem.

              oleg.kulikov Oleg Kulikov (Inactive)
              kobee1203_jira Nicolas Dos Santos (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: