Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Cloud Firestore crash on Android - MutableDocument.getKey() on null object referene

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?

like image 885
tubbytoad42 Avatar asked Apr 24 '26 15:04

tubbytoad42


1 Answers

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.

like image 129
triple7 Avatar answered Apr 27 '26 03:04

triple7