Flutter Cloud Firestore crash on Android - MutableDocument.getKey() on null object referene
It's an issue in the Firebase SDK, which has already been fixed and is waiting to be merged into FlutterFire
. You can track the issue status here, and the PR itself here.
tubbytoad42
Updated on December 19, 2022Comments
-
tubbytoad42 over 1 year
I have been struggling with a crash on a Flutter app using Cloud Firestore. During the initial load sequence of the app, it attempts to load some data from Firestore cached data. This causes the app to crash entirely, seemingly in the Android implementation of Cloud Firestore. The following error is thrown:
D/AndroidRuntime(20609): Shutting down VM E/AndroidRuntime(20609): FATAL EXCEPTION: main E/AndroidRuntime(20609): Process: com.app, PID: 20609 E/AndroidRuntime(20609): java.lang.RuntimeException: Internal error in Cloud Firestore (24.0.1). E/AndroidRuntime(20609): at com.google.firebase.firestore.util.AsyncQueue.lambda$panic$3(AsyncQueue.java:539) E/AndroidRuntime(20609): at com.google.firebase.firestore.util.-$$Lambda$AsyncQueue$cG4e8FKiBI1uHuEBYC-bY9JR88Y.run(Unknown Source:2) E/AndroidRuntime(20609): at android.os.Handler.handleCallback(Handler.java:938) E/AndroidRuntime(20609): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(20609): at android.os.Looper.loopOnce(Looper.java:226) E/AndroidRuntime(20609): at android.os.Looper.loop(Looper.java:313) E/AndroidRuntime(20609): at android.app.ActivityThread.main(ActivityThread.java:8633) E/AndroidRuntime(20609): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(20609): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567) E/AndroidRuntime(20609): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135) E/AndroidRuntime(20609): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'com.google.firebase.firestore.model.DocumentKey com.google.firebase.firestore.model.MutableDocument.getKey()' on a null object reference E/AndroidRuntime(20609): at com.google.firebase.firestore.model.mutation.MutationBatch.applyToLocalView(MutationBatch.java:117) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.LocalDocumentsView.recalculateAndSaveOverlays(LocalDocumentsView.java:164) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.LocalDocumentsView.recalculateAndSaveOverlays(LocalDocumentsView.java:195) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.LocalStore.lambda$acknowledgeBatch$3$LocalStore(LocalStore.java:310) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.-$$Lambda$LocalStore$HWVzpgIBWnr-aRwD_W4TqGD4S0s.get(Unknown Source:4) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.SQLitePersistence.runTransaction(SQLitePersistence.java:228) E/AndroidRuntime(20609): at com.google.firebase.firestore.local.LocalStore.acknowledgeBatch(LocalStore.java:301) E/AndroidRuntime(20609): at com.google.firebase.firestore.core.SyncEngine.handleSuccessfulWrite(SyncEngine.java:440) E/AndroidRuntime(20609): at com.google.firebase.firestore.core.MemoryComponentProvider$RemoteStoreCallback.handleSuccessfulWrite(MemoryComponentProvider.java:109) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.RemoteStore.handleWriteStreamMutationResults(RemoteStore.java:666) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.RemoteStore.access$500(RemoteStore.java:53) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.RemoteStore$2.onWriteResponse(RemoteStore.java:201) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.WriteStream.onNext(WriteStream.java:185) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.WriteStream.onNext(WriteStream.java:49) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.lambda$onNext$1$AbstractStream$StreamObserver(AbstractStream.java:119) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.-$$Lambda$AbstractStream$StreamObserver$agoqqrRAMtj_xK6Rj8UhjstJJXs.run(Unknown Source:4) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.AbstractStream$CloseGuardedRunner.run(AbstractStream.java:67) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.onNext(AbstractStream.java:110) E/AndroidRuntime(20609): at com.google.firebase.firestore.remote.FirestoreChannel$1.onMessage(FirestoreChannel.java:131) E/AndroidRuntime(20609): at io.grpc.internal.DelayedClientCall$DelayedListener.onMessage(DelayedClientCall.java:447) E/AndroidRuntime(20609): at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInternal(ClientCallImpl.java:656) E/AndroidRuntime(20609): at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:641) E/AndroidRuntime(20609): at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) E/AndroidRuntime(20609): at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) E/AndroidRuntime(20609): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462) E/AndroidRuntime(20609): at java.util.concurrent.FutureTask.run(FutureTask.java:266) E/AndroidRuntime(20609): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) E/AndroidRuntime(20609): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) E/AndroidRuntime(20609): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) E/AndroidRuntime(20609): at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(AsyncQueue.java:234) E/AndroidRuntime(20609): at java.lang.Thread.run(Thread.java:920) I/Process (20609): Sending signal. PID: 20609 SIG: 9
Clearing the app data will fix this, and the app will boot again. However, after a period of some use, the app will once again start crashing on boot. This leads me to believe that a piece of data is being loaded from Firestore that, when attempted to be processed by the app, causes this crash.
I'm at a bit of a loss to work out exactly why this crash is happening - does anyone have any insight or information?
-
SaNtoRiaN about 2 yearsCan you post the code that causes the error?
-
tubbytoad42 about 2 yearsThat is part of the problem, it is proving very difficult to track down the code causing the problem. There's a lot of asynchronous stuff happening at once during the app boot, and one of the data loading sequences seems to cause this issue.
-
Andres Fiesco Casasola about 2 yearsUnfortunately, the code is needed to reproduce the issue and debugging would be a lot easier. That's why SaNtoRiaN asked for the code. Could you please share your code to further assist you? I also did a search about the error you are getting and I found this similar case.
-
tubbytoad42 about 2 yearsUnfortunately part of the problem is that it's difficult to pin down which part of the code is doing it exactly. On further investigation, it seems to be an issue with pending operations in Cloud Firestore. Specifically, if network is disabled, then the crash will not occur - however, once the network is reenabled again and enableNetwork() is called on cloud Firestore, the crash happens. So some data that Firestore is trying to operate on (probably a write to server) is causing a crash.
-
Adeyemi Seun about 2 yearsHonestly this is very frustrating. Am experiencing this from some weeks now. And it usually happens when the network is bad and when network get better this unpredictable scenario happens
-