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

QueryResultIterator.skip throws NoSuchElementException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.4.0.Final
    • 4.3.0.Final
    • Query
    • None

    Description

      Hello modeshape team,

      since we've upgraded to modeshape 4.3 we're experiencing troubles using QueryResultIterator.skip(...), i.e. we get the following exception:

      java.util.NoSuchElementException
      	at org.modeshape.jcr.query.JcrQueryResult$QueryResultIterator.moveToNextRow(JcrQueryResult.java:249)
      	at org.modeshape.jcr.query.JcrQueryResult$QueryResultIterator.skip(JcrQueryResult.java:270)
      

      Originally our source looked like this (sql, offset, and maxResults are passed as parameters):

      	final QueryManager queryManager = getSession().getWorkspace().getQueryManager();
      	final Query query = queryManager.createQuery(sql, Query.JCR_SQL2);
      	final QueryResult result = query.execute();
      
      	final NodeIterator nodeIterator = result.getNodes();
      	if (nodeIterator.getSize() > offset) {
      		nodeIterator.skip(offset);
      	}
      	for (int i = 0; i < maxResults && nodeIterator.hasNext(); i++) {
      		final Node node = (Node) nodeIterator.next();
      		...
      	}
      

      Everything worked fine with modeshape 4.2, but with 4.3 we're getting a java.util.NoSuchElementException when calling nodeIterator.skip (not every time but in most of the cases).

      With some debugging we've identified the cause within org.modeshape.jcr.query.engine.process.new Batch().hasNext() which has been changed according to MODE-2435.

      @Override
          public boolean hasNext() {
      -   	return remainingRowCount.get() > 0 && rows.hasNext();
      +       return rowsLeftInBatch.get() > 0 && rows.hasNext();
          }
      

      Currently we've implemented the following workaround which works as intended:

      	final NodeIterator nodeIterator = result.getNodes();
      	if (nodeIterator.getSize() > offset) {
      		for (int i = 0; i < offset; i++) {
      			if (nodeIterator.hasNext()) {
      				nodeIterator.nextNode();
      			}
      		}
      	}
      	for (int i = 0; i < maxResults && nodeIterator.hasNext(); i++) {
      		final Node node = (Node) nodeIterator.next();
      		...
      	}
      

      It looks like currentBatch is not set to null by QueryResultIterator.hasNext() as org.modeshape.jcr.query.engine.process.new Batch().hasNext() is not using the variable 'remainingRowCount' anymore but 'rowsLeftInBatch' instead.

      Attachments

        Activity

          People

            hchiorean Horia Chiorean (Inactive)
            javagirlie Susanne Königstorfer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: