Skip to content

Commit 9969148

Browse files
authored
fix: correcting protocol parsing logic that may lead to incorrect sanitization of an incoming message from LD servers (#288)
After examining related code to a customer support case and #278, noticed this modification during iteration. Theoretical issue is that modification during iteration, even if not resulting in ConcurrentModificationExceptions, could result in unpredictable iteration and could possibly skip sanitizing certain incoming flags. Through bench testing and instrumentation testing, I was unable to reproduce the issue, but I suspect it may be dependent on the specific platform's implementation of the Map type that GSON will depend on. Will deploy this fix and work with customers to confirm if the occurrences of the issue is eliminated.
1 parent 259f07a commit 9969148

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/sdk/android/EnvironmentData.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public static EnvironmentData fromJson(String json) throws SerializationExceptio
7878
// Normalize the data set to ensure that the flag keys are present not only as map keys,
7979
// but also in each Flag object. That is normally the case in data sent by LD, even though
8080
// it's redundant, but if for any reason it isn't we can transparently fix it.
81-
for (Map.Entry<String, Flag> e: dataMap.entrySet()) {
82-
Flag f = e.getValue();
81+
for (Map.Entry<String, Flag> entry: dataMap.entrySet()) {
82+
Flag f = entry.getValue();
8383
if (f.getKey() == null) {
84-
f = new Flag(e.getKey(), f.getValue(), f.getVersion(), f.getFlagVersion(),
84+
f = new Flag(entry.getKey(), f.getValue(), f.getVersion(), f.getFlagVersion(),
8585
f.getVariation(), f.isTrackEvents(), f.isTrackReason(), f.getDebugEventsUntilDate(),
8686
f.getReason(), f.getPrerequisites());
87-
dataMap.put(e.getKey(), f);
87+
entry.setValue(f);
8888
}
8989
}
9090
return new EnvironmentData(dataMap);

0 commit comments

Comments
 (0)