Android: Sort modules by ID when serializing delta bundle

Summary:
Fixes redbox/yellowbox symbolication when the Java delta client is enabled. Previously the modules would get concatenated in a nondeterministic order (owing to Metro's parallelism) which differed from their order in the source map, where they're explicitly sorted by module ID.

This diff changes the data structure holding modules in memory from a `LinkedHashMap` (which iterates in insertion order) to a `TreeMap` (which iterates in key order).

NOTE: Similar to this change in the Chrome debugger's delta client: https://github.com/react-native-community/cli/pull/279

Reviewed By: dcaspi

Differential Revision: D15301927

fbshipit-source-id: 27bdecfb3d6963aa358e4d542c8b7663fd9eb437
This commit is contained in:
Moti Zilberman
2019-05-14 10:24:57 -07:00
committed by Facebook Github Bot
parent 4105450c7e
commit a05e9f8e09
2 changed files with 145 additions and 4 deletions
@@ -11,7 +11,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.TreeMap;
import javax.annotation.Nullable;
import android.util.JsonReader;
@@ -75,7 +75,7 @@ public abstract class BundleDeltaClient {
byte[] mPreCode;
byte[] mPostCode;
final LinkedHashMap<Number, byte[]> mModules = new LinkedHashMap<Number, byte[]>();
final TreeMap<Number, byte[]> mModules = new TreeMap<Number, byte[]>();
@Override
public boolean canHandle(ClientType type) {
@@ -146,7 +146,7 @@ public abstract class BundleDeltaClient {
return Pair.create(Boolean.TRUE, null);
}
private static int setModules(JsonReader jsonReader, LinkedHashMap<Number, byte[]> map)
private static int setModules(JsonReader jsonReader, TreeMap<Number, byte[]> map)
throws IOException {
jsonReader.beginArray();
@@ -167,7 +167,7 @@ public abstract class BundleDeltaClient {
return numModules;
}
private static int removeModules(JsonReader jsonReader, LinkedHashMap<Number, byte[]> map)
private static int removeModules(JsonReader jsonReader, TreeMap<Number, byte[]> map)
throws IOException {
jsonReader.beginArray();