Skip to content

Commit 8a15e0d

Browse files
WoLewickifacebook-github-bot
authored andcommitted
fix: singletonMap for module events (#42354)
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
1 parent 53dda9e commit 8a15e0d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModuleConstantsHelper.java

+5
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ private static void validateDirectEventNames(
193193
}
194194
}
195195
}
196+
// When providing one event in Kotlin, it will create a SingletonMap by default
197+
// which will throw on trying to add new element to it
198+
if (!(events instanceof HashMap)) {
199+
events = new HashMap(events);
200+
}
196201
for (String oldKey : keysToNormalize) {
197202
Object value = events.get(oldKey);
198203
String baseKey = "";

0 commit comments

Comments
 (0)