Fix the FlipperArray creation of events

Summary:
The FlipperArray creation from JSONArray used to create an array of `null`'s instead of the FlipperObject, which used to crash the Flipper. Thus added a check in the flipper to not crash in the case when it receives array of nulls. Also fixed the Fresco plugin in mobile to send the proper FlipperArray.

Bug:

{F160049909}

Reviewed By: passy

Differential Revision: D15608297

fbshipit-source-id: 625e017d3bce4135ac699ee5aee8d871db378749
This commit is contained in:
Pritesh Nandgaonkar
2019-06-04 03:35:14 -07:00
committed by Facebook Github Bot
parent 95fae7d4e8
commit 62c112c713
2 changed files with 19 additions and 4 deletions

View File

@@ -175,12 +175,20 @@ public class FrescoFlipperPlugin extends BufferingFlipperPlugin
getImageData( getImageData(
imageID, encodedBitmap, bitmap, mFlipperImageTracker.getUriString(cacheKey))); imageID, encodedBitmap, bitmap, mFlipperImageTracker.getUriString(cacheKey)));
} }
responder.success(
FlipperArray.Builder arrayBuilder = new FlipperArray.Builder();
for (FlipperObject obj : mEvents) {
arrayBuilder.put(obj);
}
mEvents.clear();
FlipperObject object =
new FlipperObject.Builder() new FlipperObject.Builder()
.put("levels", levels) .put("levels", levels)
.put("imageDataList", imageDataListBuilder.build()) .put("imageDataList", imageDataListBuilder.build())
.put("events", new FlipperArray(new JSONArray(mEvents))) .put("events", arrayBuilder.build())
.build()); .build();
responder.success(object);
} }
}); });
connection.receive( connection.receive(

View File

@@ -105,8 +105,15 @@ export default class extends FlipperPlugin<PluginState, *, PersistedState> {
}; };
events.forEach((event: ImageEventWithId, index) => { events.forEach((event: ImageEventWithId, index) => {
if (!event) {
return;
}
const {attribution} = event; const {attribution} = event;
if (attribution instanceof Array && attribution.length > 0) { if (
attribution &&
attribution instanceof Array &&
attribution.length > 0
) {
const surface = attribution[0].trim(); const surface = attribution[0].trim();
if (surface.length > 0) { if (surface.length > 0) {
pluginData.surfaceList.add(surface); pluginData.surfaceList.add(surface);