Tentative fix for NPE JavaTimerManager$IdleCallbackRunnable.cancel (#44852)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44852

This attempts to fix #44842 by capturing the accessed field in a new variable.
We don't have a way to reproduce this & this is a best guess fix.

Changelog:
[Android] [Fixed] - Tentative fix for NPE `JavaTimerManager$IdleCallbackRunnable.cancel`

Reviewed By: javache

Differential Revision: D58356826

fbshipit-source-id: d016df9a52f81a8d645a0a100c6bc6111841e24e
This commit is contained in:
Nicola Corti
2024-06-18 14:41:09 +02:00
committed by Thibault Malbranche
parent f4b0fcb922
commit 988bf162a0
@@ -99,8 +99,11 @@ public class JavaTimerManager {
}
// If the JS thread is busy for multiple frames we cancel any other pending runnable.
if (mCurrentIdleCallbackRunnable != null) {
mCurrentIdleCallbackRunnable.cancel();
// We also capture the idleCallbackRunnable to tentatively fix:
// https://github.com/facebook/react-native/issues/44842
IdleCallbackRunnable idleCallbackRunnable = mCurrentIdleCallbackRunnable;
if (idleCallbackRunnable != null) {
idleCallbackRunnable.cancel();
}
mCurrentIdleCallbackRunnable = new IdleCallbackRunnable(frameTimeNanos);