Firebase Push Notifications NPE

I’m getting 100s of NPEs from sending push notifications. My suspicion is that it has something to do with the image push notifications that Firebase now supports.
These crashes don’t seem to be user facing which is good. Unfortunately, Google counts crashes in app store rankings so I’m scared about the amount of crashes I’m getting.

Here’s the crash logs:

java.lang.NullPointerException: 
  at com.android.okhttp.okio.Buffer.write (Buffer.java:1182)
  at com.android.okhttp.okio.Buffer.read (Buffer.java:1221)
  at com.android.okhttp.okio.RealBufferedSource.read (RealBufferedSource.java:65)
  at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read (Http1xStream.java:602)
  at com.android.okhttp.internal.Util.skipAll (Util.java:172)
  at com.android.okhttp.internal.Util.discard (Util.java:154)
  at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.close (Http1xStream.java:619)
  at com.android.okhttp.okio.RealBufferedSource.close (RealBufferedSource.java:421)
  at com.android.okhttp.okio.RealBufferedSource$1.close (RealBufferedSource.java:409)
  at com.google.android.gms.internal.firebase_messaging.zzk.zza
  at com.google.firebase.messaging.zzi.close
  at com.google.firebase.messaging.zzb.zza
  at com.google.firebase.messaging.FirebaseMessagingService.zzc
  at com.google.firebase.messaging.zzg.run
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1167)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:641)
  at com.google.android.gms.common.util.concurrent.zza.run (Unknown Source:6)
  at java.lang.Thread.run (Thread.java:764)

This error occurs on a range of devices.

I’m sending the notifications from the Firebase console and using the latest Firebase Messaging SDK v19.0.1

7 thoughts on “Firebase Push Notifications NPE

  1. Obfuscated code is not fun to dig through but I think I’ve pinpointed the cause of the problem.

    Working backwards through the stacktrace…
    com.google.android.gms.internal.firebase_messaging.zzk.zza – Google’s logging class to catch InputStream exceptions. My best guess is that close is being called on a null InputStream and that’s the cause of the crash. IOException doesn’t catch null exceptions.
    MaxthonSnap20190926103305

    Now why would the InputStream be null?
    com.google.firebase.messaging.zzi.close, com.google.firebase.messaging.zzb.zza – Firebase’s Executor and Task used to return Bitmap to FirebaseMessagingService. The actual decoding of the input stream is a bit unclear and might be unrelated. The crash originates inside the Executor here.
    MaxthonSnap20190926104635

    com.google.firebase.messaging.FirebaseMessagingService.zzc – this function is the culprit. My guess is that a 5 second timeout forces close to be called on a null InputStream.
    MaxthonSnap20190926104324

    Mystery solved? 🤞 My takeaway is to make your image small enough to be downloadable in 5 seconds. Or else your push notifications might not have images 🙁

    Another fascinating gem, the maximum size of an image is 1048576 bytes or approximately 1MB. Should probably be documented in Firebase somewhere.
    MaxthonSnap20190926105847

  2. Comments seem to contradict one another about image sizes, for some, it fixes the issue, for others it doesn’t.

    I’ll add my two cents here – for me the issue is massive in Crashlytics but isn’t reproducible on my device. I even tried to deliberately crash it by trying to show 3mb image (notification just shows without an image) and by linking to a server that is programmed to return an image after 10 seconds, to hit the 5-sec timeout by Firebase (same as before, the notification shown without an image).

    May it be that the issue isn’t in the SDK, but rather in the Play Services installed on the device?

  3. Hi All, our engineering team continues to investigate the issue internally using this bug#141328496. I’ll let you know as soon as I have more information.