Index: src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java
===================================================================
--- src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java	(revision 550493)
+++ src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java	(working copy)
@@ -66,7 +66,7 @@
         this.session = (SessionImpl) session;
 
         addVersion(rootVersion);
-        // retrieve inital size, since size of the list is not stable
+        // retrieve initial size, since size of the list is not stable
         size = versions.size();
     }
 
@@ -134,8 +134,8 @@
     }
 
     /**
-     * Adds the version 'v' to the list of versions to return and then calls
-     * it self recursively with all the verions prodecessors.
+     * Adds the version 'v' to the list of versions to return and then iterates
+     * over the hierarchy of successors of 'v'.
      *
      * @param v
      */
@@ -140,13 +140,19 @@
      * @param v
      */
     private synchronized void addVersion(InternalVersion v) {
-        NodeId id = v.getId();
-        if (!versions.contains(id)) {
-            versions.add(id);
-            InternalVersion[] vs = v.getSuccessors();
-            for (int i = 0; i < vs.length; i++) {
-                addVersion(vs[i]);
+        LinkedList workQueue = new LinkedList();
+        workQueue.add(v);
+        while (!workQueue.isEmpty()) {
+            InternalVersion currentVersion = (InternalVersion) workQueue.removeFirst();
+            NodeId id = currentVersion.getId();
+            if (!versions.contains(id)) {
+                versions.add(id);
+                InternalVersion[] successors = currentVersion.getSuccessors();
+                for (int i = 0; i < successors.length; i++) {
+                    workQueue.add(successors[i]);
+                }
             }
         }
+
     }
 }
Index: src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java
===================================================================
--- src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java	(revision 0)
+++ src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java	(revision 0)
@@ -0,0 +1,61 @@
+package org.apache.jackrabbit.core.version;
+
+import java.util.Calendar;
+
+import junit.framework.TestCase;
+
+import org.apache.jackrabbit.core.NodeId;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.uuid.UUID;
+
+public class VersionIteratorImplTest extends TestCase {
+
+    private static final int VERSION_COUNT = 10000;
+
+    private final class DummyInternalVersion implements InternalVersion {
+
+        private final InternalVersion[] successors;
+        private NodeId id;
+
+        public DummyInternalVersion(InternalVersion[] successors, NodeId id) {
+            this.successors = successors;
+            this.id = id;
+        }
+
+        public InternalVersion[] getSuccessors() {
+            return successors;
+        }
+
+        public NodeId getId() {
+            return id;
+        }
+
+        public Calendar getCreated() {return null;}
+        public InternalFrozenNode getFrozenNode() {return null;}
+        public QName[] getLabels() {return null;}
+        public QName getName() {return null;}
+        public InternalVersion[] getPredecessors() {return null;}
+        public InternalVersionHistory getVersionHistory() {return null;}
+        public boolean hasLabel(QName label) {return false;}
+        public boolean isMoreRecent(InternalVersion v) {return false;}
+        public boolean isRootVersion() {return false;}
+        public InternalVersionItem getParent() {return null;}
+    }
+
+    public void testVersionIterator() throws Exception {
+
+        InternalVersion version = new DummyInternalVersion(new InternalVersion[] {}, new NodeId(UUID.randomUUID()));
+        for (int i = 1; i < VERSION_COUNT; i++) {
+            version = new DummyInternalVersion(new InternalVersion[] {version}, new NodeId(UUID.randomUUID()));
+        }
+
+        try {
+            VersionIteratorImpl versionIteratorImpl = new VersionIteratorImpl(null, version);
+            assertEquals(VERSION_COUNT, versionIteratorImpl.getSize());
+        } catch (StackOverflowError e) {
+            fail("Should be able to handle " + VERSION_COUNT + " versions.");
+        }
+
+    }
+
+}
