Ensure that iterating over targets never throws an exception.
[WoTNS.git] / src / main / java / net / pterodactylus / wotns / main / IdentityTargets.java
index 2eacd08..54dc660 100644 (file)
@@ -56,6 +56,7 @@ public class IdentityTargets implements Iterable<Entry<String, String>> {
 
        private void scanForTargets() {
                synchronized (targets) {
+                       targets.clear();
                        for (Entry<String, String> property : identity.getProperties().entrySet()) {
                                if (property.getKey().startsWith("tns.")) {
                                        targets.put(property.getKey().substring(4), property.getValue());
@@ -73,7 +74,10 @@ public class IdentityTargets implements Iterable<Entry<String, String>> {
         */
        @Override
        public Iterator<Entry<String, String>> iterator() {
-               return targets.entrySet().iterator();
+               synchronized (targets) {
+                       scanForTargets();
+                       return new HashMap<String, String>(targets).entrySet().iterator();
+               }
        }
 
 }