diff --git a/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java b/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java index 87411b1380..a3bdeae925 100644 --- a/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java +++ b/kahadb/src/main/java/org/apache/kahadb/util/SequenceSet.java @@ -369,11 +369,13 @@ public class SequenceSet extends LinkedNodeList implements Iterable { private Sequence currentEntry; - private long lastReturned; + private long lastReturned = -1; public SequenceIterator() { currentEntry = getHead(); - lastReturned = currentEntry.first - 1; + if (currentEntry != null) { + lastReturned = currentEntry.first - 1; + } } public boolean hasNext() { diff --git a/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java b/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java index ebc8043f4c..48c9e484f5 100644 --- a/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java +++ b/kahadb/src/test/java/org/apache/kahadb/util/SequenceSetTest.java @@ -126,4 +126,14 @@ public class SequenceSetTest { assertEquals(expected[index++], iterator.next().longValue()); } } + + @Test + public void testIteratorEmptySequenceSet() { + SequenceSet set = new SequenceSet(); + + Iterator iterator = set.iterator(); + while(iterator.hasNext()) { + fail("Should not have any elements"); + } + } }