fixed ConcurrentModificationException in shutdown GRIB cleanup

Change-Id: Ib34b98852894e8c0b9485cfb136c0af53db5a06b
This commit is contained in:
Axel Uhl committed 2017-02-08 15:46:05 +01:00
1 parent 32b3944311
commit b0661d98ee
1 file changed
+3 -4
@@ -11,7 +11,6 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -83,10 +82,10 @@ public class GribWindFieldFactoryImpl implements GribWindFieldFactory {
@Override
public synchronized void shutdown() {
for (Iterator<WeakReference<GribWindField>> i=filesToCleanWhenGribWindFieldNoLongerUsed.keySet().iterator(); i.hasNext(); ) {
final WeakReference<GribWindField> ref = i.next();
// clone key set because cleanup will remove the reference from filesToCleanWhenGribWindFieldNoLongerUsed
// which would lead to a ConcurrentModificationException otherwise.
for (final WeakReference<GribWindField> ref : new ArrayList<>(filesToCleanWhenGribWindFieldNoLongerUsed.keySet())) {
cleanup(ref);
i.remove();
}
}