Skip to content

Commit 59e7ed5

Browse files
committed
Avoid calling abstract methods in RCTComposedViewRegistry
Summary: `RCTComposedViewRegistry` extends `NSMutableDictionary` which is a clustered class in iOS. NSMutableDictionary is techncially an abstract class, but when instantiated by `[NSMutableDictionary new];` the system will return one of concrete classes that inherit from `NSMutableDictionary`, opaquely from the perspective of the caller. By calling `super`, we are actually calling the not implemented method for the abstract class. If this happen, this can crash the app. Given that the `RCTComposedViewRegistry` is extending the dictionary only for its interface but is using other mechanisms as storage, is it fair to return `NULL`if the storages don't have the requested view. ## Changelog [iOS][Fixed] - Avoid calling abstract methods in RCTComposedViewRegistry Reviewed By: cortinico Differential Revision: D56755427 fbshipit-source-id: f5c56dc59ccc6b30c00199b4196c42eb9b021e2b
1 parent 305249f commit 59e7ed5

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/react-native/React/Modules/RCTUIManager.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ - (NSEnumerator *)keyEnumerator
16931693
- (id)objectForKey:(id)key
16941694
{
16951695
if (![key isKindOfClass:[NSNumber class]]) {
1696-
return [super objectForKey:key];
1696+
return NULL;
16971697
}
16981698

16991699
NSNumber *index = (NSNumber *)key;
@@ -1705,23 +1705,22 @@ - (id)objectForKey:(id)key
17051705
if (view) {
17061706
return [RCTUIManager paperViewOrCurrentView:view];
17071707
}
1708-
return [super objectForKey:key];
1708+
return NULL;
17091709
}
17101710

17111711
- (void)removeObjectForKey:(id)key
17121712
{
17131713
if (![key isKindOfClass:[NSNumber class]]) {
1714-
return [super removeObjectForKey:key];
1714+
return;
17151715
}
1716+
17161717
NSNumber *tag = (NSNumber *)key;
17171718

17181719
if (_registry[key]) {
17191720
NSMutableDictionary *mutableRegistry = (NSMutableDictionary *)_registry;
17201721
[mutableRegistry removeObjectForKey:tag];
17211722
} else if ([_uiManager viewForReactTag:tag]) {
17221723
[_uiManager removeViewFromRegistry:tag];
1723-
} else {
1724-
[super removeObjectForKey:key];
17251724
}
17261725
}
17271726

0 commit comments

Comments
 (0)