diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-01-01 17:06:39 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-01-01 17:06:39 +0100 |
| commit | 67f776a540e883a20baa88bc24a9fd5b0dcd6b40 (patch) | |
| tree | db7105b53862571f0a81adaadf992c48e6985724 /main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java | |
| parent | 047b1b12e452c04a32318053f1506b5eb65bfcc1 (diff) | |
| download | cgeo-67f776a540e883a20baa88bc24a9fd5b0dcd6b40.zip cgeo-67f776a540e883a20baa88bc24a9fd5b0dcd6b40.tar.gz cgeo-67f776a540e883a20baa88bc24a9fd5b0dcd6b40.tar.bz2 | |
fix #2316: race condition in LeastRecentlyUsedSet
removeAll() must be synchronized as well. Otherwise, the documentation
states that it uses a (unsynchronized) iterator to perform the removal,
which causes race conditions.
Diffstat (limited to 'main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java')
| -rw-r--r-- | main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java index 98aba03..b654fd6 100644 --- a/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java +++ b/main/src/cgeo/geocaching/utils/LeastRecentlyUsedSet.java @@ -2,6 +2,7 @@ package cgeo.geocaching.utils; import java.util.AbstractSet; import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -102,6 +103,18 @@ public class LeastRecentlyUsedSet<E> extends AbstractSet<E> } /** + * Synchronized removal of all elements contained in another collection. + */ + @Override + public synchronized boolean removeAll(final Collection<?> c) { + boolean changed = false; + for (final Object o: c) { + changed |= remove(o); + } + return changed; + } + + /** * Synchronized clearing of the set * Copy of the HashSet code if clear() * |
