lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ehatc...@apache.org
Subject svn commit: r164726 - in /lucene/java/trunk/src: java/org/apache/lucene/search/HitIterator.java test/org/apache/lucene/TestHitIterator.java
Date Tue, 26 Apr 2005 03:19:08 GMT
Author: ehatcher
Date: Mon Apr 25 20:19:07 2005
New Revision: 164726

URL: http://svn.apache.org/viewcvs?rev=164726&view=rev
Log:
Fix issue Otis identified with HitIterator, along with corresponding test case

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/HitIterator.java
    lucene/java/trunk/src/test/org/apache/lucene/TestHitIterator.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/HitIterator.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/java/org/apache/lucene/search/HitIterator.java?rev=164726&r1=164725&r2=164726&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/HitIterator.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/HitIterator.java Mon Apr 25 20:19:07
2005
@@ -50,13 +50,12 @@
    * @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;
   }
 
   /**

Modified: lucene/java/trunk/src/test/org/apache/lucene/TestHitIterator.java
URL: http://svn.apache.org/viewcvs/lucene/java/trunk/src/test/org/apache/lucene/TestHitIterator.java?rev=164726&r1=164725&r2=164726&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/TestHitIterator.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/TestHitIterator.java Mon Apr 25 20:19:07
2005
@@ -13,6 +13,8 @@
 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 @@
     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);
   }
 }



Mime
View raw message