diff --git a/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java b/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java index 48d0dc8444c..536b1cfe48d 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestDocsAndPositions.java @@ -171,8 +171,9 @@ public class TestDocsAndPositions extends LuceneTestCase { } if (random().nextInt(10) == 0) { // once is a while advance - docsAndPosEnum - .advance(docID + 1 + random().nextInt((maxDoc - docID))); + if (docsAndPosEnum.advance(docID + 1 + random().nextInt((maxDoc - docID))) == DocIdSetIterator.NO_MORE_DOCS) { + break; + } } } while (docsAndPosEnum.nextDoc() != DocIdSetIterator.NO_MORE_DOCS);