diff --git a/source/de/anomic/kelondro/kelondroRotateIterator.java b/source/de/anomic/kelondro/kelondroRotateIterator.java index eb31f5d46..7e55d50d3 100644 --- a/source/de/anomic/kelondro/kelondroRotateIterator.java +++ b/source/de/anomic/kelondro/kelondroRotateIterator.java @@ -47,6 +47,9 @@ public class kelondroRotateIterator implements kelondroCloneableIterator { } public Object next() { + // attention: this iterator has no termination - on purpose. + // it must be taken care that a calling method has a termination predicate different + // from the hasNext() method if (!(a.hasNext())) { a = (kelondroCloneableIterator) clone.clone(modifier); } diff --git a/source/de/anomic/plasma/plasmaWordIndex.java b/source/de/anomic/plasma/plasmaWordIndex.java index 9a088eb0e..c3d93de8d 100644 --- a/source/de/anomic/plasma/plasmaWordIndex.java +++ b/source/de/anomic/plasma/plasmaWordIndex.java @@ -496,14 +496,18 @@ public final class plasmaWordIndex implements indexRI { Iterator i = wordContainers(startHash, ram, rot); if (ram) count = Math.min(dhtOutCache.size(), count); indexContainer container; + // this loop does not terminate using the i.hasNex() predicate when rot == true + // because then the underlying iterator is a rotating iterator without termination + // in this case a termination must be ensured with a counter + // It must also be ensured that the counter is in/decreased every loop while ((count > 0) && (i.hasNext())) { container = (indexContainer) i.next(); if ((container != null) && (container.size() > 0)) { containers.add(container); - count--; } + count--; // decrease counter even if the container was null or empty to ensure termination } - return containers; + return containers; // this may return less containers as demanded } public kelondroCloneableIterator wordContainers(String startHash, boolean ram, boolean rot) {