firebase-android-sdk icon indicating copy to clipboard operation
firebase-android-sdk copied to clipboard

Firebase Push Notifications NPE

Open rayliverified opened this issue 7 years ago • 34 comments

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

rayliverified avatar Aug 14 '19 23:08 rayliverified

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.

google-oss-bot avatar Aug 14 '19 23:08 google-oss-bot

@searchy2 i am also facing exactly same issue

hariiprasad avatar Aug 17 '19 12:08 hariiprasad

I am also facing this issue, any clue?

BlackHei avatar Aug 19 '19 07:08 BlackHei

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?

ciarand avatar Aug 19 '19 19:08 ciarand

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

hariiprasad avatar Aug 20 '19 01:08 hariiprasad

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.

rayliverified avatar Aug 26 '19 15:08 rayliverified

@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

duncancarroll avatar Aug 27 '19 18:08 duncancarroll

@searchy2 did you find a solution?

turgayulutas avatar Aug 29 '19 06:08 turgayulutas

anyone have solution?

BlackHei avatar Aug 29 '19 12:08 BlackHei

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

turgayulutas avatar Aug 29 '19 13:08 turgayulutas

We're seeing the same issue on our side, with images in push notifications. The images are hosted by a 3rd party service.

littleariel avatar Sep 11 '19 20:09 littleariel

We solved this by reducing the image sizes, unfortunately firebase not handles large images

IevgenOsetrov avatar Sep 12 '19 09:09 IevgenOsetrov

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

littleariel avatar Sep 12 '19 14:09 littleariel

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

vedprakashwagh avatar Sep 13 '19 07:09 vedprakashwagh

@littleariel I think its actual image size in kb, we reduced the width to 200px and height proportionally and it solved the problem

IevgenOsetrov avatar Sep 13 '19 09:09 IevgenOsetrov

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

littleariel avatar Sep 13 '19 15:09 littleariel

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

rayliverified avatar Sep 26 '19 16:09 rayliverified

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

duncancarroll avatar Sep 26 '19 18:09 duncancarroll

same issue here, even if image size < 1MB (around 180k)

ksc91u avatar Oct 07 '19 02:10 ksc91u

stesso problema qui, anche se la dimensione dell'immagine <1 MB (circa 180 k)

cabanel avatar Oct 07 '19 16:10 cabanel