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 2021/03/15 17:41:59 UTC
[uima-uimaj] 01/01: [UIMA-6342] Moving iterator beyond bounds does
not invalidate it
This is an automated email from the ASF dual-hosted git repository.
rec pushed a commit to branch bugfix/UIMA-6342-Moving-iterator-beyond-bounds-does-not-invalidate-it
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 6fbaab487acce1d124aaf2d24cde3e55446b2c1e
Author: Richard Eckart de Castilho <re...@apache.org>
AuthorDate: Mon Mar 15 18:41:46 2021 +0100
[UIMA-6342] Moving iterator beyond bounds does not invalidate it
- Added unit test
- First attempt at fixing it
---
.../java/org/apache/uima/cas/impl/Subiterator.java | 31 +++++++++++++++++++---
.../org/apache/uima/cas/impl/SelectFsTest.java | 28 ++++++++++++++++++-
2 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
index 19cbb76..0969fd5 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/Subiterator.java
@@ -803,7 +803,9 @@ public class Subiterator<T extends AnnotationFS> implements LowLevelIterator<T>
@Override
public void moveToNoReinit(FeatureStructure fs) {
- if (isEmpty) return;
+ if (isEmpty) {
+ return;
+ }
// unambiguous must be in list form
if (isUnambiguous && !isListForm) {
@@ -820,7 +822,7 @@ public class Subiterator<T extends AnnotationFS> implements LowLevelIterator<T>
// Always bounded (if unbounded, that's only when subiterator is being used to
// implement "unambiguous", and that mode requires the "list" form above.)
// can be one of 3 bounds: coveredBy, covering, and sameBeginEnd.
- //moveTo_iterators(fs);
+ //moveTo_iterators(fs, false);
moveTo_iterators_legacy(fs);
}
@@ -871,6 +873,26 @@ public class Subiterator<T extends AnnotationFS> implements LowLevelIterator<T>
return;
}
+ // Check if the move went outside the bounds
+ switch (boundsUse) {
+ case covering:
+ if (is_beyond_bounds_chk_coveringNvc()) {
+ return;
+ }
+ case coveredBy:
+ if (is_beyond_bounds_chk_coveredByNvc()) {
+ return;
+ }
+ case sameBeginEnd:
+ if (is_beyond_bounds_chk_sameBeginEnd()) {
+ return;
+ }
+ case notBounded:
+ default:
+ // No check necessary
+ break;
+ }
+
// CASE: If the iterator is pointing on the bounds annotation, we must first skip this in
// forward direction to ensure we find a potentially matching FSes occurring in the indexes
// after the bounds annotation.
@@ -1068,7 +1090,10 @@ public class Subiterator<T extends AnnotationFS> implements LowLevelIterator<T>
(isUseTypePriority && a._getTypeImpl() != boundType)) {
makeInvalid();
return true;
- } else return false;
+ }
+ else {
+ return false;
+ }
}
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
index 83c1802..4ca5c81 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/impl/SelectFsTest.java
@@ -51,7 +51,6 @@ import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.XMLInputSource;
import org.junit.Before;
import org.junit.FixMethodOrder;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
@@ -1777,6 +1776,33 @@ public class SelectFsTest {
assertThat(it.isValid()).isTrue();
}
+ @Test
+ public void thatSeekingIteratorToOutOfIndexPositionOnRightIsInvalid() throws Exception {
+ TypeSystemDescription tsd = getResourceSpecifierFactory().createTypeSystemDescription();
+ tsd.addType("test.Type1", "", CAS.TYPE_NAME_ANNOTATION);
+ tsd.addType("test.Type2", "", CAS.TYPE_NAME_ANNOTATION);
+ tsd.addType("test.Type3", "", CAS.TYPE_NAME_ANNOTATION);
+
+ CAS cas = CasCreationUtils.createCas(tsd, null, null, null);
+
+ Type type1 = cas.getTypeSystem().getType("test.Type1");
+ Type type2 = cas.getTypeSystem().getType("test.Type2");
+ Type type3 = cas.getTypeSystem().getType("test.Type3");
+
+ AnnotationFS window, seekPoint;
+ addToIndexes(
+ window = cas.createAnnotation(type1, 0, 10),
+ cas.createAnnotation(type2, 5, 6),
+ seekPoint = cas.createAnnotation(type3, 8, 9),
+ cas.createAnnotation(type2, 15, 16));
+
+ FSIterator<AnnotationFS> it = cas.getAnnotationIndex(type2).select().coveredBy(window).fsIterator();
+
+ it.moveTo(seekPoint);
+
+ assertThat(it.isValid()).isFalse();
+ }
+
@SuppressWarnings("unchecked")
private static <T extends AnnotationFS, R extends AnnotationFS> List<R> toListBackwards(
SelectFSs<T> select) {