Attempt to invoke virtual method 'void com.facebook.react.uimanager.UlManagerModule.onBatchComplete()' on a null object reference
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
まず、uilib-native/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/ 配下の react-native-ui-lib/react-native.config.js と RuntimeUtils.java を調べます。記載されている React Native とパッケージのバージョンで Android キーボードの操作を再現し、その後、両方のパッケージソースが更新され、UIManagerModule が利用できない場合にクラッシュが発生しなくなったことを確認します。
索引モデルが issue の本文から書いたものです。
説明
Description
Android crashes due to NullPointerException in RuntimeUtils.java when using the keyboard input features. The issue stems from the React Native UI Lib package's dependency structure for Android, where patches need to be applied to both react-native-ui-lib AND uilib-native packages.
Related to
- Components
- Demo
- Docs
- Typings
Steps to reproduce
- Use
react-native-ui-libin a React Native application - Implement components that use keyboard-related features
- Run on Android
- App crashes with
NullPointerExceptioninRuntimeUtils.javaduring keyboard interaction - Apply patch to
react-native-ui-libbut crashes continue
Expected behavior
The app should handle keyboard interactions properly without crashing.
Actual behavior
The app crashes with errors like:
Fatal Exception: java.lang.NullPointerException
Attempt to invoke virtual method 'void com.facebook.react.uimanager.UIManagerModule.onBatchComplete()' on a null object reference
at com.wix.reactnativeuilib.keyboardinput.utils.RuntimeUtils$1.run(RuntimeUtils.java:13)
More Info
Root Cause Analysis
The root cause of this issue is a non-obvious relationship between react-native-ui-lib and uilib-native packages.
When building the Android app, the react-native-ui-lib package doesn't use its own native Android code. Instead, it points to the uilib-native package's Android code, as configured in react-native-ui-lib/react-native.config.js:
// node_modules/react-native-ui-lib/react-native.config.js
module.exports = {
dependency: {
platforms: {
android: {
sourceDir: "../uilib-native/android/",
// Other config...
},
},
},
};
This means that patching only react-native-ui-lib doesn't affect the Android build, since it's actually using code from uilib-native.
Code snippet
Original problematic code in uilib-native:
// node_modules/uilib-native/android/src/main/java/com/wix/reactnativeuilib/keyboardinput/utils/RuntimeUtils.java
package com.wix.reactnativeuilib.keyboardinput.utils;
import com.facebook.react.uimanager.UIManagerModule;
import com.wix.reactnativeuilib.keyboardinput.ReactContextHolder;
public class RuntimeUtils {
private static final Runnable sUIUpdateClosure = new Runnable() {
@Override
public void run() {
ReactContextHolder.getContext().getNativeModule(UIManagerModule.class).onBatchComplete();
}
};
public static void runOnUIThread(Runnable runnable) {
if (ReactContextHolder.getContext() != null) {
ReactContextHolder.getContext().runOnUiQueueThread(runnable);
}
}
public static void dispatchUIUpdates(final Runnable userRunnable) {
runOnUIThread(new Runnable() {
@Override
public void run() {
userRunnable.run();
if (ReactContextHolder.getContext() != null) {
ReactContextHolder.getContext().runOnNativeModulesQueueThread(sUIUpdateClosure);
}
}
});
}
}
Fixed version with proper null checks:
package com.wix.reactnativeuilib.keyboardinput.utils;
import android.util.Log;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.uimanager.UIManagerModule;
import com.wix.reactnativeuilib.keyboardinput.ReactContextHolder;
public class RuntimeUtils {
private static final Runnable sUIUpdateClosure = new Runnable() {
@Override
public void run() {
try {
ReactContext context = ReactContextHolder.getContext();
if (context != null) {
UIManagerModule uiManager = context.getNativeModule(UIManagerModule.class);
if (uiManager != null) {
uiManager.onBatchComplete();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
public static void runOnUIThread(Runnable runnable) {
try {
if (ReactContextHolder.getContext() != null) {
ReactContextHolder.getContext().runOnUiQueueThread(runnable);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void dispatchUIUpdates(final Runnable userRunnable) {
if (ReactContextHolder.getContext() == null) {
return; // Skip if context is null
}
try {
runOnUIThread(new Runnable() {
@Override
public void run() {
try {
// Re-check context before running user code
if (ReactContextHolder.getContext() != null) {
userRunnable.run();
// Get a fresh context reference before queue operation
ReactContext context = ReactContextHolder.getContext();
if (context != null) {
context.runOnNativeModulesQueueThread(sUIUpdateClosure);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
Solution
To fix this issue, you need to patch both packages using patch-package:
- First, patch
react-native-ui-lib - Then, patch
uilib-native - Apply both patches using
patch-packagein your postinstall script
Example patches are provided in the code snippets above.
Verification
To verify that patches are correctly applied:
- Check that both package source files contain your patches
- Add Log statements in the patched code (like
Log.d("TAG", "message")) - Monitor the Android logs during app execution to confirm the patched code is running
Screenshots/Video
N/A
Environment
- React Native version: 0.76.x
- React Native UI Lib version: 7.38.1
- uilib-native version: 4.5.1 (indirectly used by react-native-ui-lib)
Affected platforms
- Android
- iOS
- Web
Reference: https://github.com/facebook/react-native/issues/47662
- 主要言語
- TypeScript
- スター
- 7.2k
- フォーク
- 749
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
wix/react-native-ui-lib のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
wix/react-native-ui-lib#4022 ·
メンテナーはふだん 1 日以内に返信
-
SortableGridList does not forward props to its inner ScrollView (inconsistent with SortableList)対応中かも @yinminqian が 174 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
wix/react-native-ui-lib#4002 ·
メンテナーはふだん 1 日以内に返信
-
RN 0.85.0 StyleSheet.absoluteFillObject is removed対応中かも @ChrisJamesC が 81 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
wix/react-native-ui-lib#3965 · コメント 3 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
asBaseComponent: stale module-level colorScheme prevents re-render on scheme switch back対応中かも @huytdps13400 が 35 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
wix/react-native-ui-lib#3945 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
wix/react-native-ui-lib#4044 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
wix/react-native-ui-lib の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
earendil-works/pi-claude-code#36 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Resources: New work of jabodetabek対応中かも @rmt-svc が今日担当しました。 オープンresources
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
railmapgen/rmp-gallery#4167 ·
メンテナーはふだん 2 日以内に返信
-
documentation p1
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
microsoft/monaco-editor#5577 ·
メンテナーはふだん 1 日以内に返信