Firebase-android-sdk: Firebase Push Notifications NPE

Created on 15 Aug 2019  Â·  34Comments  Â·  Source: firebase/firebase-android-sdk

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

messaging needs-info

Most helpful comment

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.

All 34 comments

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.
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

@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)

I am also facing this,and the session in background is crashing

any update for this issue?

i have same problem

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.zzj.close at com.google.firebase.messaging.zzd.zza at com.google.firebase.messaging.FirebaseMessagingService.zzc at com.google.firebase.messaging.zze.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)

@ashwinraghav @ciarand Any update on a fix for this? It's our #1 crash even after reducing image sizes to 512x512 JPGs (~20kb). Thanks!

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?

We are getting similar hundreds of crashes, when sending image notifications through firebase console. Unable to reproduce locally, but 100+ crashes on crashlytics

Several months later there's no fix. Can we at least get some feedback?

We have been getting it too and reported under https://github.com/firebase/firebase-android-sdk/issues/1006. Even after changing the images to be 512x256 the issue still comes. The images are around ~12kb, one being at 8kb. I don't think reducing image sizes helps at all.

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.

The issue has been identified and fixed internally. Currently waiting when would be the external release date.

Hi All, we released a new version of our Cloud Messaging SDK, see release notes. Please try update to latest 20.1.0 to see whether there is still such issue?

Hi All, we released a new version of our Cloud Messaging SDK, see release notes. Please try update to latest 20.1.0 to see whether there is still such issue?

Crashlytics will still report NPE, which accounts for about 1% of the total。
implementation 'com.google.firebase:firebase-messaging:20.1.0'

hi @longyuan5 could you confirm if the issue persists?

I can confirm it is resolved in 20.1.0. Thanks team!

Thanks. Closing this issue for now.

In case you guys still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Was this page helpful?
0 / 5 - 0 ratings