unwrap the recursion when removing orphan references. this caused a stack overflow exception if a thew thousand references where empty

This commit is contained in:
Andreas Perhab 2013-03-22 13:08:01 +01:00
parent c74e3da2dd
commit 54b3154ddc

View File

@ -88,9 +88,10 @@ public class ConcurrentSet<T> implements Iterable<T>{
public boolean hasNext() {
if (current == null) return false;
T value = current.getValue();
if (value == null) { // auto-removal of orphan references
remove();
if (current.getValue() == null) { // auto-removal of orphan references
do {
remove();
} while(current != null && current.getValue() == null);
return hasNext();
} else {
return true;
@ -101,7 +102,9 @@ public class ConcurrentSet<T> implements Iterable<T>{
if (current == null) return null;
T value = current.getValue();
if (value == null) { // auto-removal of orphan references
remove();
do {
remove();
} while(current != null && current.getValue() == null);
return next();
} else {
current = current.next();