From 18373e1129ae5dbbf1e492a0cf74425cf0207a32 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 16 Aug 2016 16:12:55 -0400 Subject: [PATCH] LUCENE-7414: TestUtil.checkIterator can make tests very slow --- .../src/java/org/apache/lucene/util/TestUtil.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java index b63216085b3..19fcb3bfffb 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestUtil.java @@ -177,11 +177,14 @@ public final class TestUtil { assert hasNext; T v = iterator.next(); assert allowNull || v != null; - try { - iterator.remove(); - throw new AssertionError("broken iterator (supports remove): " + iterator); - } catch (UnsupportedOperationException expected) { - // ok + // for the first element, check that remove is not supported + if (i == 0) { + try { + iterator.remove(); + throw new AssertionError("broken iterator (supports remove): " + iterator); + } catch (UnsupportedOperationException expected) { + // ok + } } } assert !iterator.hasNext();