itinance / itinance/react-native-fs
Bug Report(Android): prevent NullPointerException crash when Promise.reject receives null code
- Dominant language
- C++
- Stars
- 5k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Hi!
Firstly, thanks for your work on this project!
### Issue Description
**Description**
When calling certain file system methods on Android (e.g., `RNFSManager`), the app crashes on the native side if an exception is thrown.
The underlying cause is that `RNFSManager` passes `null` as the first argument to `promise.reject(null, ex.getMessage())`. Newer versions of React Native implement `PromiseImpl` in Kotlin, where the `code` parameter is strictly defined as non-null (`@NotNull`). Passing `null` causes Kotlin's runtime assertion to throw an unhandled `NullPointerException` on the Android main thread, crashing the application before the error can be handled in JavaScript.
### Environment
- React native 0.83.1
- react-native-fs 2.20
**Stacktrace**
```text
Fatal Exception: java.lang.NullPointerException
Parameter specified as non-null is null: method com.facebook.react.bridge.PromiseImpl.reject, parameter code
at com.facebook.react.bridge.PromiseImpl.reject(PromiseImpl.kt:2)
at com.rnfs.RNFSManager.reject(RNFSManager.java:978)
at com.rnfs.RNFSManager.access$000(RNFSManager.java:60)
```
Here is the diff that solved my problem:
```diff
--- a/node_modules/react-native-fs/android/src/main/java/com/rnfs/RNFSManager.java
+++ b/node_modules/react-native-fs/android/src/main/java/com/rnfs/RNFSManager.java
@@ -975,7 +975,7 @@ public class RNFSManager extends ReactContextBaseJavaModule {
return;
}
- promise.reject(null, ex.getMessage());
+ promise.reject("EUNSPECIFIED", ex.getMessage());
}
private void rejectFileNotFound(Promise promise, String filepath) {
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in android/src/main/java/com/rnfs/RNFSManager.java around line 978, where the stack trace identifies the rejection path, and review the React Native Promise.reject contract in the reported environment. Exercise a failing Android file-system call and confirm that the exception reaches JavaScript as a handled rejection without a native NullPointerException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java, react-native
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 85/100