Skip to content

Commit

Permalink
fix: singletonMap for module events (#42354)
Browse files Browse the repository at this point in the history
Summary:
Sometimes the events map can be a of type `SingletonMap` which will cause this code to throw exception when adding keys to it, so we change it to normal `HashMap`. Creating `SingletonMap` can especially happen in Kotlin when there is only one event added to a map, see:
https://github.com/plaid/react-native-plaid-link-sdk/blob/5ffab5eef576163528f0da504181162da3bef08b/android/src/main/java/com/plaid/PLKEmbeddedViewManager.kt#L21
## Changelog:

[ANDROID] [FIXED] - Cover SingletonMap when parsing events exported by module

Pull Request resolved: #42354

Test Plan: Create `getExportedCustomBubblingEventTypeConstants` as `SingletonMap` in some example module and see that the code does not throw.

Reviewed By: cipolleschi

Differential Revision: D58417266

Pulled By: cortinico

fbshipit-source-id: 6c46398ddf4d044386a36d0c1663bd071d642fb6
  • Loading branch information
WoLewicki authored and facebook-github-bot committed Jun 11, 2024
1 parent 53dda9e commit 8a15e0d
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ private static void validateDirectEventNames(
}
}
}
// When providing one event in Kotlin, it will create a SingletonMap by default
// which will throw on trying to add new element to it
if (!(events instanceof HashMap)) {
events = new HashMap(events);
}
for (String oldKey : keysToNormalize) {
Object value = events.get(oldKey);
String baseKey = "";
Expand Down

0 comments on commit 8a15e0d

Please sign in to comment.