[main] Fix obvious race condition in weak collections
This commit is contained in:
parent
eb71fb6533
commit
b8d496f716
|
@ -18,9 +18,11 @@ public class WeakSet<E> extends AbstractSet<E> {
|
|||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (delegate.hasNext()) {
|
||||
next = unwrap(delegate.next());
|
||||
return true;
|
||||
synchronized (WeakSet.this) {
|
||||
if (delegate.hasNext()) {
|
||||
next = unwrap(delegate.next());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ public class WeakSet<E> extends AbstractSet<E> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
public synchronized void clear() {
|
||||
processQueue();
|
||||
delegate.clear();
|
||||
}
|
||||
|
|
|
@ -187,10 +187,12 @@ public class WeakValueMap<K, V> implements Map<K, V> {
|
|||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
if (delegate.hasNext()) {
|
||||
Entry<K, WeakValue<K, V>> ent = delegate.next();
|
||||
next = new DelegateEntry(ent, unwrap(ent.getValue()));
|
||||
return true;
|
||||
synchronized (WeakValueMap.this) {
|
||||
if (delegate.hasNext()) {
|
||||
Entry<K, WeakValue<K, V>> ent = delegate.next();
|
||||
next = new DelegateEntry(ent, unwrap(ent.getValue()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue