Fix issue Otis identified with HitIterator, along with corresponding test case

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@164726 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2005-04-26 03:19:07 +00:00
parent 2bb0c8f257
commit cfd5d55b7e
2 changed files with 17 additions and 6 deletions

View File

@ -50,13 +50,12 @@ public class HitIterator implements Iterator {
* @return Next {@link Hit}.
*/
public Object next() {
try {
Object next = new Hit(hits, hitNumber);
hitNumber++;
return next;
} catch (IndexOutOfBoundsException e) {
if (hitNumber == hits.length())
throw new NoSuchElementException();
}
Object next = new Hit(hits, hitNumber);
hitNumber++;
return next;
}
/**

View File

@ -13,6 +13,8 @@ import org.apache.lucene.search.Hits;
import org.apache.lucene.search.Hit;
import org.apache.lucene.search.HitIterator;
import java.util.NoSuchElementException;
/**
* This test intentionally not put in the search package in order
* to test HitIterator and Hit package protection.
@ -46,5 +48,15 @@ public class TestHitIterator extends TestCase {
assertEquals("iterator test doc 2", hit.getDocument().get("field"));
assertFalse(iterator.hasNext());
boolean caughtException = false;
try {
iterator.next();
} catch (NoSuchElementException e) {
assertTrue(true);
caughtException = true;
}
assertTrue(caughtException);
}
}