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

fix: NPE when removing single location updates #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ifarhanpatel
Copy link

@ifarhanpatel ifarhanpatel commented Apr 14, 2023

Overview

When getting the location from playServices, the app crashes for some users. Not able to reproduce it.
It has also been reported Here

#Crash Log
Fatal Exception: java.lang.NullPointerException: Listener must not be null at com.google.android.gms.common.internal.Preconditions.checkNotNull(SourceFile:2) at com.google.android.gms.common.api.internal.ListenerHolders.createListenerKey(SourceFile:1) at com.google.android.gms.location.FusedLocationProviderClient.removeLocationUpdates(SourceFile:6) at o.computeScrollRange$4.onLocationResult(SourceFile:74) at com.google.android.gms.internal.location.zzaw.notifyListener(SourceFile:2) at com.google.android.gms.common.api.internal.ListenerHolder.zaa(SourceFile:2) at com.google.android.gms.common.api.internal.zacb.run(:4) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:257) at android.app.ActivityThread.main(ActivityThread.java:8183) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1015)

Test Plan

I'm assuming the fix is straightforward. We deployed a patch of this in our app with success.

@MarkCSmith
Copy link

I encountered this bug after upgrading from version 3.0.2 to version 3.0.6 of this package. One easy way to reproduce it is to have your app make a second call to getCurrentPosition() before the first call has finished. The mSingleLocationCallback member variable is overwritten when the second call is made (therefore losing track of the first LocationCallback). The mSingleLocationCallback member is set to null when one of the getCurrentPosition() calls finishes finding a location. Then, when the second "get position" call finishes finding a location, null is passed to mFusedLocationClient.removeLocationUpdates() and the Listener must not be null exception occurs.

A little re-architecture might be a good idea, e.g., maintain a list of pending getCurrentPosition() callbacks instead of making a new call to mFusedLocationClient.requestLocationUpdates() for each call an app makes.

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

Successfully merging this pull request may close these issues.

None yet

3 participants