You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by re...@apache.org on 2013/08/10 23:01:10 UTC

svn commit: r1512822 - /uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java

Author: rec
Date: Sat Aug 10 21:01:10 2013
New Revision: 1512822

URL: http://svn.apache.org/r1512822
Log:
[UIMA-3179] JCasIterable destroys reader on hasNext()
- call destroy() in hasNext() only if an error occurs
- save one call to hasNext() in next().
- call hasNext() in next() only when some auto-mode is enabled

Modified:
    uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java

Modified: uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java
URL: http://svn.apache.org/viewvc/uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java?rev=1512822&r1=1512821&r2=1512822&view=diff
==============================================================================
--- uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java (original)
+++ uima/sandbox/uimafit/trunk/uimafit-core/src/main/java/org/apache/uima/fit/pipeline/JCasIterator.java Sat Aug 10 21:01:10 2013
@@ -96,14 +96,17 @@ public class JCasIterator implements Ite
   }
 
   public boolean hasNext() {
+    boolean error = true;
     try {
-      return collectionReader.hasNext();
+      boolean hasOneMore = collectionReader.hasNext();
+      error = false;
+      return hasOneMore;
     } catch (CollectionException e) {
       throw new IllegalStateException(e);
     } catch (IOException e) {
       throw new IllegalStateException(e);
     } finally {
-      if (selfDestroy) {
+      if (error && selfDestroy) {
         destroy();
       }
     }
@@ -119,13 +122,16 @@ public class JCasIterator implements Ite
         engine.process(jCas);
       }
 
-      if (!hasNext() && selfComplete) {
-        collectionProcessComplete();
-      }
-
-      if (!hasNext() && selfDestroy) {
-        destroy();
-        destroyed = true;
+      // Only call hasNext() if auto complete or destroy is enabled.
+      if ((selfComplete || selfDestroy) && !hasNext()) {
+        if (selfComplete) {
+          collectionProcessComplete();
+        }
+
+        if (selfDestroy) {
+          destroy();
+          destroyed = true;
+        }
       }
 
       error = false;