Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: pkg/serialization/lib/src/format.dart

Issue 12210151: Fix modification of map while iterating in SimpleJsonFormat (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/pkg.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/serialization/lib/src/format.dart
diff --git a/pkg/serialization/lib/src/format.dart b/pkg/serialization/lib/src/format.dart
index ab602c92a2b80c29997324b736f7a592c07b1f08..fd6b10f59899d2fe646d46b28e09d12de3676a66 100644
--- a/pkg/serialization/lib/src/format.dart
+++ b/pkg/serialization/lib/src/format.dart
@@ -151,12 +151,20 @@ class SimpleJsonFormat extends Format {
/**
* For one particular entry, which is either a Map or a List, update it
- * to turn References into a nested List/Map.
+ * to turn References into a nested List/Map. If it's a Map, and the key
Jennifer Messerly 2013/02/13 02:07:41 Unless this is purely an internal type, I'd put th
Alan Knight 2013/02/13 22:40:31 Done.
+ * might be a reference, we need to bend over backwards to avoid
+ * concurrent modifications.
*/
jsonifyEntry(map, Writer w) {
+ var keysToRemove = [];
+ var updates = new Map();
keysAndValues(map).forEach((key, value) {
- if (value is Reference) map[key] = w.stateForReference(value);
+ var newKey = (key is Reference) ? w.stateForReference(key) : key;
+ if (value is Reference) updates[newKey] = w.stateForReference(value);
+ if (key != newKey) keysToRemove.add(key);
Jennifer Messerly 2013/02/13 02:07:41 We weren't removing keys before--is this also a bu
Alan Knight 2013/02/13 22:40:31 I added that, because one of the symptoms was an u
});
+ keysToRemove.forEach((each) => map.remove(each));
+ updates.forEach((k, v) => map[k] = v);
}
/**
« no previous file with comments | « pkg/pkg.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698