firebase / firebase-android-sdk

Firebase Android SDK
https://firebase.google.com
Apache License 2.0
2.23k stars 566 forks source link

java.lang.IllegalArgumentException a lot of them being logged in google play console #1830

Closed AbdullahNasim00 closed 2 years ago

AbdullahNasim00 commented 3 years ago

We have started getting the following exception which is only logged in google play console. Not sure about the exact issue but seems like a bug in FirebaseMessagingService SDK.

java.lang.IllegalArgumentException: at com.android.okhttp.okio.RealBufferedSource.read (RealBufferedSource.java:53) at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.read (Http1xStream.java:641) at com.android.okhttp.internal.Util.skipAll (Util.java:177) at com.android.okhttp.internal.Util.discard (Util.java:159) at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.close (Http1xStream.java:674) at com.android.okhttp.okio.RealBufferedSource.close (RealBufferedSource.java:422) at com.android.okhttp.okio.RealBufferedSource$1.close (RealBufferedSource.java:410) at com.google.android.gms.internal.firebase_messaging.zzi.zza at com.google.firebase.messaging.ImageDownload.close at com.google.firebase.messaging.DisplayNotification.waitForAndApplyImageDownload at com.google.firebase.messaging.DisplayNotification.handleNotification at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent at com.google.firebase.messaging.FirebaseMessagingService.handleIntent at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run (Unknown Source:6) 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:919)

google-oss-bot commented 3 years ago

I found a few problems with this issue:

zwu52 commented 3 years ago

@AbdullahNasim00 thanks for reporting. Can you let us know what SDK version(s) are seeing this issue?

AbdullahNasim00 commented 3 years ago

The issue was there till we were using the following SDKs:

implementation 'com.google.firebase:firebase-core:17.4.4' implementation 'com.google.firebase:firebase-messaging:20.2.3'

In the latest update we have updated the SDKs to:

implementation 'com.google.firebase:firebase-core:17.4.4' implementation 'com.google.firebase:firebase-messaging:20.2.4'

It's still there in the latest SDK.

We started getting this exception from the time we started adding image to our notification. Hope it helps.

premacck commented 3 years ago

@AbdullahNasim00 I'm also getting a similar kind of crash whenever sending notifications with images, using firebase messaging 20.3.0, so far it has been observed on various devices running android 9 and 10.

Fatal Exception: java.lang.IllegalArgumentException: byteCount < 0: -901
       at com.android.okhttp.okio.RealBufferedSource.read(RealBufferedSource.java:46)
       at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.read(Http1xStream.java:439)
       at com.android.okhttp.internal.Util.skipAll(Util.java:159)
       at com.android.okhttp.internal.Util.discard(Util.java:141)
       at com.android.okhttp.internal.http.Http1xStream$ChunkedSource.close(Http1xStream.java:472)
       at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:396)
       at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:396)
       at com.android.okhttp.okio.InflaterSource.close(InflaterSource.java:126)
       at com.android.okhttp.okio.GzipSource.close(GzipSource.java:182)
       at com.android.okhttp.okio.RealBufferedSource.close(RealBufferedSource.java:396)
       at com.android.okhttp.okio.RealBufferedSource$1.close(RealBufferedSource.java:384)
       at com.google.android.gms.internal.firebase_messaging.zzi.zza(zzi.java:4)
       at com.google.firebase.messaging.ImageDownload.close(ImageDownload.java:37)
       at com.google.firebase.messaging.DisplayNotification.waitForAndApplyImageDownload(DisplayNotification.java:53)
       at com.google.firebase.messaging.DisplayNotification.handleNotification(DisplayNotification.java:28)
       at com.google.firebase.messaging.FirebaseMessagingService.dispatchMessage(FirebaseMessagingService.java:76)
       at com.google.firebase.messaging.FirebaseMessagingService.passMessageIntentToSdk(FirebaseMessagingService.java:55)
       at com.google.firebase.messaging.FirebaseMessagingService.handleMessageIntent(FirebaseMessagingService.java:34)
       at com.google.firebase.messaging.FirebaseMessagingService.handleIntent(FirebaseMessagingService.java:23)
       at com.google.firebase.messaging.EnhancedIntentService.lambda$processIntent$0$EnhancedIntentService(EnhancedIntentService.java:43)
       at com.google.firebase.messaging.EnhancedIntentService$$Lambda$0.run(EnhancedIntentService.java:6)
       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(zza.java:6)
       at java.lang.Thread.run(Thread.java:764)

One thing I noticed in the stacktrace was this line: at com.google.firebase.messaging.ImageDownload.close(ImageDownload.java:37) and I took a look at the close method in ImageDownload class:

    public void close() {
        try {
            zzi.zza(this.connectionInputStream);
        } catch (NullPointerException var2) {
            Log.e("FirebaseMessaging", "Failed to close the image download stream.", var2);
        }
    }

It is only handling NullPointerException and not IllegalArgumentException @zwu52 is it possible to add a catch block for IllegalArgumentException as well?

In the meanwhile what I've implemented is I've overridden the handleIntent(Intent) method in my class that is extending FirebaseMessagingService like this:

override fun handleIntent(p0: Intent?) {
  try {
    super.handleIntent(p0)
  } catch (e: Exception) {
    Log.e(e)
    // Do something with the intent in case of failure, like showing our own customized notification
  }
}

@zwu52 would this be a good idea?

gsakakihara commented 2 years ago

This should be fixed in the latest version of the SDK.