Skip to content

Commit f500f42

Browse files
Yqwedmeta-codesync[bot]
authored andcommitted
Do not synchronize on java.lang.Boolean. (#56196)
Summary: ## Summary: Do not synchronize on java.lang.Boolean. Once JEP 401 is implemented synchronization on value classes (which box classes are) will throw IdentityException. In general synchronization on 1) mutable field 2) box class is inefficient (instances are shared) at best and a bug at worst case as synchronization is done holding different monitors (it might be fine, but is hard to reason about). ## Changelog: [ANDROID] [FIXED] Use explicit `ReactInstanceManager.mHasStartedDestroyingLock` instead of using `ReactInstanceManager.mHasStartedDestroying` <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests Pull Request resolved: #56196 Test Plan: GHA Reviewed By: cortinico Differential Revision: D110168816 Pulled By: javache fbshipit-source-id: dae081dc00a94859f19dcc3607971a9c3d6fbd44
1 parent 61db78d commit f500f42

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public interface ReactInstanceEventListener
170170
// Identifies whether the instance manager destroy function is in process,
171171
// while true any spawned create thread should wait for proper clean up before initializing
172172
private volatile Boolean mHasStartedDestroying = false;
173+
private final Object mHasStartedDestroyingLock = new Object();
173174
private final MemoryPressureRouter mMemoryPressureRouter;
174175
private final @Nullable JSExceptionHandler mJSExceptionHandler;
175176
private final @Nullable UIManagerProvider mUIManagerProvider;
@@ -779,8 +780,8 @@ public void destroy() {
779780
ResourceDrawableIdHelper.getInstance().clear();
780781

781782
mHasStartedDestroying = false;
782-
synchronized (mHasStartedDestroying) {
783-
mHasStartedDestroying.notifyAll();
783+
synchronized (mHasStartedDestroyingLock) {
784+
mHasStartedDestroyingLock.notifyAll();
784785
}
785786
synchronized (mPackages) {
786787
mViewManagerNames = null;
@@ -1136,10 +1137,10 @@ private void runCreateReactContextOnNewThread(final ReactContextInitParams initP
11361137
null,
11371138
() -> {
11381139
ReactMarker.logMarker(REACT_CONTEXT_THREAD_END);
1139-
synchronized (ReactInstanceManager.this.mHasStartedDestroying) {
1140+
synchronized (ReactInstanceManager.this.mHasStartedDestroyingLock) {
11401141
while (ReactInstanceManager.this.mHasStartedDestroying) {
11411142
try {
1142-
ReactInstanceManager.this.mHasStartedDestroying.wait();
1143+
ReactInstanceManager.this.mHasStartedDestroyingLock.wait();
11431144
} catch (InterruptedException e) {
11441145
// Interrupted while waiting for destruction to complete, just retry
11451146
continue;

0 commit comments

Comments
 (0)