Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Crash: FileReaderModule.readAsText java.lang.NullPointerException #45277

Closed
JinYuSha0 opened this issue Jul 4, 2024 · 2 comments
Closed
Labels
Resolution: PR Submitted A pull request with a fix has been provided.

Comments

@JinYuSha0
Copy link

Description

I see a lot of these crashes in Google Crashlytics:

Fatal Exception: java.lang.NullPointerException
Attempt to invoke interface method 'java.lang.String com.facebook.react.bridge.ReadableMap.getString(java.lang.String)' on a null object reference
com.facebook.react.modules.blob.FileReaderModule.readAsText (FileReaderModule.java:53)
java.lang.reflect.Method.invoke (Method.java)
com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188)
com.facebook.jni.NativeRunnable.run (NativeRunnable.java)
android.os.Handler.handleCallback (Handler.java:958)

android.os.Handler.dispatchMessage (Handler.java:99)
com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
android.os.Looper.loopOnce (Looper.java:230)

android.os.Looper.loop (Looper.java:319)
com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
java.lang.Thread.run (Thread.java:1012)

Locate the following code:
https://github.com/facebook/react-native/blob/main/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/blob/FileReaderModule.java#L47

The judgment of blob is not very good.

Steps to reproduce

 const fr = new FileReader();
 fr.readAsText({});

React Native Version

0.70.1

Affected Platforms

Runtime - Android

Output of npx react-native info

System:
    OS: Windows 10 10.0.19045
    CPU: (6) x64 Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz
    Memory: 6.13 GB / 15.88 GB
  Binaries:
    Node: 20.13.1 - C:\Program Files\nodejs\node.EXE    
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD    
    npm: 10.5.2 - C:\Program Files\nodejs\npm.CMD       
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
    Windows SDK:
      AllowDevelopmentWithoutDevLicense: Enabled
      AllowAllTrustedApps: Enabled
  IDEs:
    Android Studio: AI-233.14808.21.2331.11709847
    Visual Studio: Not Found
  Languages:
    Java: 17.0.11 - C:\Program Files\Microsoft\jdk-17.0.11.9-hotspot\bin\javac.EXE
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.1.0 => 18.1.0
    react-native: 0.70.14 => 0.70.14
    react-native-windows: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Stacktrace or Logs

Fatal Exception: java.lang.NullPointerException
Attempt to invoke interface method 'java.lang.String com.facebook.react.bridge.ReadableMap.getString(java.lang.String)' on a null object reference
com.facebook.react.modules.blob.FileReaderModule.readAsText (FileReaderModule.java:53)
java.lang.reflect.Method.invoke (Method.java)
com.facebook.react.bridge.JavaMethodWrapper.invoke (JavaMethodWrapper.java:372)
com.facebook.react.bridge.JavaModuleWrapper.invoke (JavaModuleWrapper.java:188)
com.facebook.jni.NativeRunnable.run (NativeRunnable.java)
android.os.Handler.handleCallback (Handler.java:958)

android.os.Handler.dispatchMessage (Handler.java:99)
com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage (MessageQueueThreadHandler.java:27)
android.os.Looper.loopOnce (Looper.java:230)

android.os.Looper.loop (Looper.java:319)
com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run (MessageQueueThreadImpl.java:228)
java.lang.Thread.run (Thread.java:1012)

Reproducer

https://github.com/JinYuSha0/FileReaderReproducer

Screenshots and Videos

No response

@github-actions github-actions bot added the Type: Unsupported Version Issues reported to a version of React Native that is no longer supported label Jul 4, 2024
Copy link

github-actions bot commented Jul 4, 2024

⚠️ Unsupported Version of React Native
ℹ️ It looks like your issue or the example you provided uses an unsupported version of React Native.

Due to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please upgrade to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on StackOverflow to get further community support.

@JinYuSha0 JinYuSha0 changed the title Crash: FileReaderModule.readAsText java.lang.NullPointerException [Android] Crash: FileReaderModule.readAsText java.lang.NullPointerException Jul 4, 2024
@cortinico cortinico added Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Author Feedback Type: Unsupported Version Issues reported to a version of React Native that is no longer supported labels Jul 4, 2024
@cortinico
Copy link
Contributor

Yup that's a valid bugreport 👍 Thanks for the reproducer @JinYuSha0 A fix is forthcoming

cortinico added a commit to cortinico/react-native that referenced this issue Jul 4, 2024
Summary:
Fixes facebook#45277

This fixes an NPE reported in OSS if you do this call in JavaScript:

```
 const fr = new FileReader();
 fr.readAsText({});
```

Changelog:
[Android] [Fixed] - Fix NPE in FileReaderModule

Differential Revision: D59372620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: PR Submitted A pull request with a fix has been provided.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants