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

Attempt to invoke virtual method 'void executeProviderCommand(int, int)' on a null object reference #280

Closed
TimurAsayonok opened this issue Sep 14, 2018 · 11 comments

Comments

@TimurAsayonok
Copy link

Your Environment

  • Plugin version: 0.5.0-alpha.40
  • Platform: Android
  • OS version: from Android 5.0
  • Device manufacturer and model: -
  • React Native version: 0.52.2
  • Plugin configuration options: I'm using default configuration options
  • Link to your project: -

Context

We use our application on production with more than 100+ users per week. About 30% users on android has problem with
Unable to pause activity {com.shopper_app/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference.

We use react-native-background-geolocation lib for getting user localization on background and for this task we use getCurrentLocation(success, fail, options) method.

Expected Behavior

We can get localization and application won't be crashed

Actual Behavior

We can't get localizationa and get fatal error on sentry system bug report

Possible Fix


Steps to Reproduce

Context

About 30% android users are getting this error and crush, it's big problem for us

Debug logs

Unable to pause activity {com.shopper_app/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
    at com.marianhello.bgloc.BackgroundGeolocationFacade.switchMode(BackgroundGeolocationFacade.java:413)
    at com.marianhello.bgloc.BackgroundGeolocationFacade.pause(BackgroundGeolocationFacade.java:304)
    at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostPause(BackgroundGeolocationModule.java:114)
    at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:214)
    at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState(ReactInstanceManager.java:700)
    at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:534)
    at com.reactnativenavigation.react.NavigationReactGateway.onPauseActivity(NavigationReactGateway.java:79)
    at com.reactnativenavigation.controllers.NavigationActivity.onPause(NavigationActivity.java:162)
    at android.app.Activity.performPause(Activity.java:6815)
    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3906)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3883)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3857)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3831)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6361)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
java.lang.RuntimeException: Unable to pause activity {com.shopper_app/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3924)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3883)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3857)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3831)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1584)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6361)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)

@equesteo
Copy link

equesteo commented Sep 17, 2018

I hit the same error yesterday.

java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
    at com.marianhello.bgloc.BackgroundGeolocationFacade.switchMode(BackgroundGeolocationFacade.java:413)
    at com.marianhello.bgloc.BackgroundGeolocationFacade.pause(BackgroundGeolocationFacade.java:304)
    at com.marianhello.bgloc.react.BackgroundGeolocationModule.onHostPause(BackgroundGeolocationModule.java:114)
    at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:212)
    at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState(ReactInstanceManager.java:662)
    at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:486)
    at com.reactnativenavigation.react.NavigationReactGateway.onPauseActivity(NavigationReactGateway.java:79)
    at com.reactnativenavigation.controllers.NavigationActivity.onPause(NavigationActivity.java:162)
    at android.app.Activity.performPause(Activity.java:6824)
    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3769)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3746)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3720)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3694)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
    at com.facebook.react.bridge.ReactContext.handleException(ReactContext.java:311)
    at com.facebook.react.bridge.ReactContext.onHostPause(ReactContext.java:214)
    at com.facebook.react.ReactInstanceManager.moveToBeforeResumeLifecycleState(ReactInstanceManager.java:662)
    at com.facebook.react.ReactInstanceManager.onHostPause(ReactInstanceManager.java:486)
    at com.reactnativenavigation.react.NavigationReactGateway.onPauseActivity(NavigationReactGateway.java:79)
    at com.reactnativenavigation.controllers.NavigationActivity.onPause(NavigationActivity.java:162)
    at android.app.Activity.performPause(Activity.java:6824)
    at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1323)
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3769)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3746)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3720)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3694)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

java.lang.RuntimeException: Unable to pause activity {com.equesteo/com.reactnativenavigation.controllers.NavigationActivity}: java.lang.RuntimeException: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.marianhello.bgloc.LocationService.executeProviderCommand(int, int)' on a null object reference
    at android.app.ActivityThread.performPauseActivityIfNeeded(ActivityThread.java:3780)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3746)
    at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3720)
    at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3694)
    at android.app.ActivityThread.-wrap16(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1508)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6186)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

@TimurAsayonok
Copy link
Author

@mauron85 Could you help us?

@mauron85
Copy link
Owner

Is this happening also on latest alpha?

@TimurAsayonok
Copy link
Author

@mauron85 I will update to latest version on this week and will test on the production. I will write to you later

@fhassanpur
Copy link

I'm also running into this issue. One of the virtual devices doesn't experience it but the other and my real device does. However, it's strange because the AVD that crashes is running Android 5.0.2, my real device is running 8.1, but the AVD that doesn't crash is running 6.0.

Enviornment:

  • Plugin version: 0.5.0-alpha.48
  • Platform: Android
  • OS version: from Android 8.1, 5.0.2
  • Device manufacturer and model: - ONEPLUS A5010 (5T) - 8.1.0, PIXEL_API_21(AVD) - 5.0.2
  • React Native version: 0.55.3
  • Plugin configuration options: default

@mauron85
Copy link
Owner

It would be helpful if you can write down steps how to replicate, or at least some preconditions leading to crash (eg. app terminated but running in bg, ...). The more info, the better.

@TimurAsayonok
Copy link
Author

@mauron85 We have updated and publish new public version of our application. We will try to get more information

@fhassanpur
Copy link

fhassanpur commented Sep 28, 2018

The application was crashing on startup, I believe as the native components were being loaded by the React Native bridge.

I was able to find a temporary fix, but I'm not sure what kind of effect it will have on the system overall.

In BackgroundGeolocationFacade.java, I found that the checking for null before calling switchMode() in pause() seemed to keep it from crashing.

    public void pause() {
        if (mService != null)
        {
            switchMode(BackgroundGeolocationFacade.BACKGROUND_MODE);
        }
        unbindService();
    }

Technically, this change needs to be in the background-geolocation-android repo. I'm not too familiar with the service lifecycle, but this should be okay right?

@mauron85
Copy link
Owner

@fhassanpur thanks for good lead. After some investigation I think the crash is caused when service is not yet connected/created and app is moving to background. So that null check is perfect fix and just workaround.

@mauron85
Copy link
Owner

I'm going to pull this PR which will also fix this.
https://github.com/mauron85/background-geolocation-android/pull/17/files

@mauron85
Copy link
Owner

Should be fixed in alpha.42. Closing for now. Please feel free to reopen when necessary.

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

No branches or pull requests

4 participants