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 - Exception in HostObject::get(propName:ReactNativeBlobUtil) #34

Closed
cristianoccazinsp opened this issue May 15, 2021 · 5 comments

Comments

@cristianoccazinsp
Copy link

cristianoccazinsp commented May 15, 2021

Version: 0.13.7
OS: Android 11 (Samsung Note 10+)
Possibly related to: #33

The following crash is happening randomly (seen from our reporting tool) on android while the app is in background, presumably right before getting killed:

com.facebook.react.common.JavascriptException: Error: Exception in HostObject::get(propName:ReactNativeBlobUtil): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object reference, stack:
<unknown>@856:161
v@2:1473
<unknown>@855:127
v@2:1473
<unknown>@852:176
v@2:1473
<unknown>@851:173
v@2:1473
<unknown>@804:153
v@2:1473
<unknown>@431:408
v@2:1473
d@2:875
<unknown>@6:1625
y@11:586
<unknown>@11:1889
y@11:586
o@11:1065
<unknown>@11:1208
f@127:154
<unknown>@127:881
x@132:655
y@132:1019
callImmediates@132:3084
callImmediates@-1
value@43:3106
<unknown>@43:1282
value@43:2798
value@43:1252
value@-1
value@-1

        at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:79)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
        at com.facebook.react.bridge.queue.NativeRunnable.run(NativeRunnable.java:-2)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
        at android.os.Looper.loop(Looper.java:246)
        at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
        at java.lang.Thread.run(Thread.java:923)

Basically, this:

com.facebook.react.common.JavascriptException: Error: Exception in HostObject::get(propName:ReactNativeBlobUtil): java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.io.File.getAbsolutePath()' on a null object

Looking at the breadcrumbs, it looks like the user opened the app, but it never entered in foreground mode. The app works fine with normal use, and all permissions are properly defined in manifest and whatsoever.

I'm also loading some folders from the config.js file (loaded pretty much right after app start) like this:

import ReactNativeBlobUtil from 'react-native-blob-util';

// this is basically somewhere else so there's no hard dependencies to the library
let fs = {};
fs.ls = ReactNativeBlobUtil.fs.ls;
fs.mkdir = ReactNativeBlobUtil.fs.mkdir;
fs.df = ReactNativeBlobUtil.fs.df;
fs.dirs = ReactNativeBlobUtil.fs.dirs;

...

const DOCS_DIR = fs.dirs.DocumentDir;
const CACHE_DIR = fs.dirs.CacheDir;
const DOCS_DIR_S = DOCS_DIR + '/';
@cristianoccazinsp
Copy link
Author

Crash is most likely happening from here or its surroundings, as this is the only place the reported method is called on app startup:

https://github.com/RonRadtke/react-native-blob-util/blob/master/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java#L253

From the stack trace, it is impossible to tell which getAbsolutePath failed.

@RonRadtke
Copy link
Owner

Which react-native version are you using?
Thank you for the information.
Then we probably have to wrap this part of the code too, so it won't fail.

But the questions is, how can that fail. The dictionaries we try to access should exist by default for every app on andorid or ios.

@cristianoccazinsp
Copy link
Author

RN 0.62.2

I think the fail may be very rare, and it can be blamed on Android itself. Perhaps the crash itself is better than falling back to a default value, but at least a better message should be provided.

@cristianoccazinsp
Copy link
Author

Looks like this is still happening and over time more consistently:

image

Last one was from android 11 on a samsung Note 10+

@RonRadtke
Copy link
Owner

I wrapped both now in methods. This should prevent the app from crashing.
But this also means it could be that you get an empty string instead of a filepath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants