Skip to content

Commit f00795d

Browse files
JoshuaGrossfacebook-github-bot
authored andcommitted
Prevent NPE in measure during measure/teardown race
Summary: When stopSurface is called, Fabric might be processing a commit and performing measurements even as the context is being removed from the FabricUIManager map. Just return a 0 from `measure` if we can't get a context. This prevents crashes during teardown for measured views that will never be visible anyway. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D22604716 fbshipit-source-id: 67be8d272afd35fc4c2b51b371939c5623e97f73
1 parent ee8a0cf commit f00795d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java

+11
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,19 @@ private long measure(
466466
float minHeight,
467467
float maxHeight,
468468
@Nullable float[] attachmentsPositions) {
469+
470+
// This could be null if teardown/navigation away from a surface on the main thread happens
471+
// while a commit is being processed in a different thread. By contract we expect this to be
472+
// possible at teardown, but this race should *never* happen at startup.
473+
@Nullable
469474
ReactContext context =
470475
rootTag < 0 ? mReactApplicationContext : mReactContextForRootTag.get(rootTag);
476+
477+
// Don't both measuring if we can't get a context.
478+
if (context == null) {
479+
return 0;
480+
}
481+
471482
return mMountingManager.measure(
472483
context,
473484
componentName,

0 commit comments

Comments
 (0)