In firebase console I can see crash events with error:
Fatal Exception: java.lang.RuntimeException: Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@ee59593 with null: java.lang.IllegalArgumentException: invalid null provider
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4794)
at android.app.ActivityThread.access$2000(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2196)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8595)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by java.lang.IllegalArgumentException: invalid null provider
at com.android.internal.util.Preconditions.checkArgument(Preconditions.java:52)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:927)
at com.marianhello.bgloc.provider.RawLocationProvider.onStart(RawLocationProvider.java:49)
at com.marianhello.bgloc.service.LocationServiceImpl$3.run(LocationServiceImpl.java:366)
at org.chromium.content.browser.ThreadUtils.runOnUiThreadBlocking(ThreadUtils.java:27)
at com.marianhello.bgloc.service.LocationServiceImpl.start(LocationServiceImpl.java:363)
at com.marianhello.bgloc.service.LocationServiceImpl.onStartCommand(LocationServiceImpl.java:274)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4776)
at android.app.ActivityThread.access$2000(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2196)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8595)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Expected Behavior
Exception can be handled properly
Actual Behavior
App crashes with error
Fatal Exception: java.lang.RuntimeException
Unable to start service com.marianhello.bgloc.service.LocationServiceImpl@ee59593 with null: java.lang.IllegalArgumentException: invalid null provider
The try {} catch {} block only handles SecurityException but should also handle any exception .
Also, there should be a check of getBestProvider function call result.
Your Environment
Context
In firebase console I can see crash events with error:
Expected Behavior
Exception can be handled properly
Actual Behavior
App crashes with error
Possible Fix
Error happens in https://github.com/mauron85/background-geolocation-android/blob/58464febf6901f1e489817e4425418d48443929b/src/main/java/com/marianhello/bgloc/provider/RawLocationProvider.java#L49 because system somehow can't find suitable location provider and
locationManager.getBestProvider(criteria, true)
returnsnull
:The
try {} catch {}
block only handlesSecurityException
but should also handle any exception . Also, there should be a check ofgetBestProvider
function call result.Steps to Reproduce
1. 2. 3. 4.
Context
Debug logs