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
I found a few problems with this issue:
- I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
- This issue does not seem to follow the issue template. Make sure you provide all the required information.
@searchy2 i am also facing exactly same issue
I am also facing this issue, any clue?
Hey folks, thanks for reporting this. Some followup questions:
- @searchy2 do you have a proguard map for the above stack? It looks like it might have been proguarded twice, so it's difficult to tell exactly where the failure is coming from
- @ everyone else: you're using the new image support, right? what sort of image types / sizes / etc. are you using? are these being uploaded via the console or are you referencing files that are hosted elsewhere?
hey @ciarand in My case the image format is jpg and i am just referencing that files from github( i placed the push Notification images in my github) .
The images I've used are all PNGs uploaded to Firebase Storage.
There is no Proguard active in my app and any obfuscation is probably done by the Firebase SDK itself. The error log looks readable to me and I've seen it in other places on the internet.
@ciarand What new image support are you referring to? I encounter this with most notifications that include images. Some of these images can be large-ish, so it's possible they are running into some time limit on decode / download (I think I saw a logcat message re: that locally.) If I have time I'll try reproducing it with a curl and report back.
When we decode these on the app side with the data {} payload, this error never occurs, it's only when the OS attempts to parse the notification {} body on it's own.
Re: obfuscation, it's not being double-proguarded, that's the lib itself's proguarding.
OP left out the message which is:
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
@searchy2 did you find a solution?
anyone have solution?
@BlackHei , I've been sending .gif with notification. I've canceled gif posting and I'm only sending .png and .jpeg notifications. I'm not sure, but since I stopped sending .gif, there was no error.
We're seeing the same issue on our side, with images in push notifications. The images are hosted by a 3rd party service.
We solved this by reducing the image sizes, unfortunately firebase not handles large images
@Osjack thanks for the info! Anything you could share regarding the max size that seems to work? Is it a kb size or resolution limitation?
Yeah I've been having this issue lately, I googled the problem but couldn't find any solution. I've added question on StackOverflow regarding this issue. I've already added reducing image size as a possible solution, if you have anything that worked for you, I'll be glad to add it. Here's the question: https://stackoverflow.com/questions/57893795/nullpointerexception-only-on-very-very-few-devices-after-sending-push-notificati/57918864#57918864
@littleariel I think its actual image size in kb, we reduced the width to 200px and height proportionally and it solved the problem
@Osjack thanks! We'll keep that in mind if we decide to use images again, but will probably hold off until this is resolved on the Firebase SDK side.
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.

Now why would the InputStream be null?
com.google.firebase.messaging.zzi.close, com.google.firebase.messaging.zzb.zza - Firebase's Executor and Task
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.

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.

@searchy2 Good find. A 1MB limit pretty much excludes full-resolution PNGs as many phones are 1024px wide, and a 1024x1024 PNG is nearly 2MB coming out of Photoshop.
@ciarand It would be awesome if this could be documented. If nothing else, a null check on the InputStream would be a good patch, as Ray indicated it may be affecting Play Store rankings.
same issue here, even if image size < 1MB (around 180k)
stesso problema qui, anche se la dimensione dell'immagine <1 MB (circa 180 k)