Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okio.Segment.limit' on a null object reference
at com.android.okio.OkBuffer.write + 574(OkBuffer.java:574)
at com.android.okio.OkBuffer.read + 610(OkBuffer.java:610)
at com.android.okio.RealBufferedSource.read + 56(RealBufferedSource.java:56)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read + 469(HttpConnection.java:469)
at com.android.okhttp.internal.Util.skipAll + 227(Util.java:227)
at com.android.okhttp.internal.http.HttpConnection.discard + 239(HttpConnection.java:239)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.close + 491(HttpConnection.java:491)
at com.android.okio.RealBufferedSource.close + 204(RealBufferedSource.java:204)
at com.android.okio.RealBufferedSource$1.close + 187(RealBufferedSource.java:187)
at com.google.android.gms.internal.firebase_messaging.zzk.zza + 4(zzk.java:4)
at com.google.firebase.messaging.zzd.close + 37(zzd.java:37)
at com.google.firebase.messaging.zzc.zzas + 51(zzc.java:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzd + 59(FirebaseMessagingService.java:59)
at com.google.firebase.iid.zzb.run + 2(zzb.java:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1112(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 587(ThreadPoolExecutor.java:587)
at com.google.android.gms.common.util.concurrent.zza.run + 6(zza.java:6)
at java.lang.Thread.run + 818(Thread.java:818)
This issue does not seem to follow the issue template. Make sure you provide all the required information.
implementation 'com.google.firebase:firebase-core:16.0.9'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
@Yonghejiunian sorry for my slow response here (I was on vacation) but can you give some more information on how to reproduce this issue?
Related: https://github.com/square/okio/issues/79
Still can't reproduce the issue, however our Crashlytics shows 4% crash sessions. All the session are in the background, different Android API and devices.

Same issue with;
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Its happen only when you add image in notification
Related issue https://github.com/firebase/firebase-android-sdk/issues/709
Hey @Yonghejiunian. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Can you give some more information on how to reproduce this issue?
Seems like any push notification from Firebase throws this. Also after dependencies update.
The strange thing I do not receive fatal crash, notification works fine and received by service properly. So its encountered as crash on Crashlytics, but it does not fatal crash for the app.
Steps to reproduce for me:
I filed issue https://github.com/firebase/firebase-android-sdk/issues/709
What's interesting is that I'm getting this error instead of the one I filed after reducing the image size to around 50KB with a width of 480px.
Error:
Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
com.android.okhttp.okio.Buffer.write
Here's my stack trace:
com.android.okhttp.okio.Buffer.write (Buffer.java:1182)
com.android.okhttp.okio.Buffer.read (Buffer.java:1221)
com.android.okhttp.okio.RealBufferedSource.read (RealBufferedSource.java:55)
com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read (Http1xStream.java:393)
com.android.okhttp.internal.Util.skipAll (Util.java:159)
com.android.okhttp.internal.Util.discard (Util.java:141)
com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.close (Http1xStream.java:410)
com.android.okhttp.okio.RealBufferedSource.close (RealBufferedSource.java:396)
com.android.okhttp.okio.RealBufferedSource$1.close (RealBufferedSource.java:384)
com.google.android.gms.internal.firebase_messaging.zzk.zza (com.google.firebase:firebase-messaging@@20.0.0:4)
com.google.firebase.messaging.zzj.close (com.google.firebase:firebase-messaging@@20.0.0:38)
com.google.firebase.messaging.zzd.zza (com.google.firebase:firebase-messaging@@20.0.0:51)
com.google.firebase.messaging.FirebaseMessagingService.zzc (com.google.firebase:firebase-messaging@@20.0.0:60)
com.google.firebase.messaging.zze.run (com.google.firebase:firebase-messaging@@20.0.0:2)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
com.google.android.gms.common.util.concurrent.zza.run (Unknown Source:6)
java.lang.Thread.run (Thread.java:764)
What could be the issue?
I removed the image from notification, however still I got crash reports.
Hey @Yonghejiunian. We need more information to resolve this issue but there hasn't been an update in 7 days. I'm marking the issue as stale and if there are no new updates in the next 3 days I will close it automatically.
If you have more information that will help us get to the bottom of this, just add a comment!
Since there haven't been any recent updates here, I am going to close this issue.
@Yonghejiunian if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.
Also getting this error using dependencies
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0
I am facing the same issue. I pin pointed the method that is giving error in firebase messaging library.
```
public final boolean zzb(Intent var1) {
if ("com.google.firebase.messaging.NOTIFICATION_OPEN".equals(var1.getAction())) {
PendingIntent var3;
if ((var3 = (PendingIntent)var1.getParcelableExtra("pending_intent")) != null) {
try {
var3.send();
} catch (CanceledException var4) {
Log.e("FirebaseMessaging", "Notification pending intent canceled");
}
}
if (MessagingAnalytics.shouldUploadMetrics(var1)) {
MessagingAnalytics.logNotificationOpen(var1);
}
return true;
} else {
return false;
}
}
```
What do you think is root cause? any ideas?
Same error for me
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0
Why is it closed? The issue isn't resolved!
Same error for me
implementation 'com.google.firebase:firebase-core:17.2.0' implementation 'com.google.firebase:firebase-messaging:20.0.0Why is it closed? The issue isn't resolved!
That's because nobody cares. My suggestion don't use images in notifications when you send them from Firebase console, instead send data messages using API and handle image loading by yourself
This is really sad that so many users faced the same issue but still we don’t have a solution. Firebase team should do something in future updates. For time being i will not use the images.
@ashwinraghav we're seeing this issue with customers of the Unity SDK as well https://github.com/firebase/quickstart-unity/issues/508 could you escalate?
Fatal Exception: java.lang.NullPointerException
Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
com.android.okhttp.okio.Buffer.write
Same issue. Couldn' find out what causes the problem.
For my case just one phone (LG Premier Pro with Android 8) encountered with the crash
Facing similar issues in Android app (haveing firebase sdk). Sending notification in images via firebase console.
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
at com.android.okhttp.okio.Buffer.write + 1182(Buffer.java:1182)
at com.android.okhttp.okio.Buffer.read + 1221(Buffer.java:1221)
at com.android.okhttp.okio.RealBufferedSource.read + 65(RealBufferedSource.java:65)
at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read + 602(Http1xStream.java:602)
at com.android.okhttp.internal.Util.skipAll + 172(Util.java:172)
at com.android.okhttp.internal.Util.discard + 154(Util.java:154)
at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.close + 619(Http1xStream.java:619)
at com.android.okhttp.okio.RealBufferedSource.close + 421(RealBufferedSource.java:421)
at com.android.okhttp.okio.RealBufferedSource$1.close + 409(RealBufferedSource.java:409)
at com.google.android.gms.internal.firebase_messaging.zzk.a + 4(:4)
at com.google.firebase.messaging.zzd.close + 37(:37)
at com.google.firebase.messaging.zzc.a + 51(:51)
at com.google.firebase.messaging.FirebaseMessagingService.c + 59(:59)
at com.google.firebase.iid.zzb.run + 2(:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1167(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 641(ThreadPoolExecutor.java:641)
at com.google.android.gms.common.util.concurrent.zza.run + 6(:6)
at java.lang.Thread.run + 764(Thread.java:764)
Hello, we've been facing similar issues as well. Again, when sending a notification with image which in our case is done by having { notification: { ..., image: "...." } } as payload :
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
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(com.google.firebase:firebase-messaging@@20.0.0:4)
at com.google.firebase.messaging.zzj.close(com.google.firebase:firebase-messaging@@20.0.0:38)
at com.google.firebase.messaging.zzd.zza(com.google.firebase:firebase-messaging@@20.0.0:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.0.0:60)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.0.0:2)
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(:6)
at java.lang.Thread.run(Thread.java:764)
I am seeing a similar crashlog when using image in a notification
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
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:55)
at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:393)
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$FixedLengthSource.close(Http1xStream.java:410)
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.zzk.zza(zzk.java:4)
at com.google.firebase.messaging.zzj.close(zzj.java:38)
at com.google.firebase.messaging.zzd.zza(zzd.java:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(FirebaseMessagingService.java:60)
at com.google.firebase.messaging.zze.run(zze.java:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(zza.java:6)
at java.lang.Thread.run(Thread.java:784)
I am seeing the same issue as well.
implementation 'com.google.firebase:firebase-analytics:17.2.0'
implementation 'com.google.firebase:firebase-messaging:20.0.0'
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
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(zzk.java:4)
at com.google.firebase.messaging.zzj.close(zzj.java:38)
at com.google.firebase.messaging.zzd.zza(zzd.java:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(FirebaseMessagingService.java:60)
at com.google.firebase.messaging.zze.run(zze.java:2)
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)
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Transferred this issue to the firebase-android-sdk repo since that's the best place for it.
cc @ashwinraghav
hey , last month we use the CMPP protocol, no crash, but CMPP protocol not support Big Image, we have to use the http protocol again (default protocol type), this issue come back again ,about 4%-5%, this is a so bad problem, why no one fix it? i have to Dismantling the arr ,then add try catch or remove "final" in that bad method to override ,when i make ,i will reply again!
@Yonghejiunian sorry for my slow response here (I was on vacation) but can you give some more information on how to reproduce this issue?
I Dismantling the aar(firebase-messaging-18.0.0.aar) make it come to local(firebase-messaging-18.0.0_fixcrash.aar) , add "try catch " and remove "final" in method "public void zzd(Intent var1) ", now is ok ,no crash ,i will make a ABTest, hope you fix this bug, many developers has such issue!
My app also has the same issue from the last few months.
There are ~3500 crashes related to that and all are because of the image in the notification from Firebase console.
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okio.Segment.limit' on a null object reference
at com.android.okio.OkBuffer.write(OkBuffer.java:574)
at com.android.okio.OkBuffer.read(OkBuffer.java:610)
at com.android.okio.RealBufferedSource.read(RealBufferedSource.java:56)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read(HttpConnection.java:469)
at com.android.okhttp.internal.Util.skipAll(Util.java:227)
at com.android.okhttp.internal.http.HttpConnection.discard(HttpConnection.java:239)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.close(HttpConnection.java:491)
at com.android.okio.RealBufferedSource.close(RealBufferedSource.java:204)
at com.android.okio.RealBufferedSource$1.close(RealBufferedSource.java:187)
at f.d.a.b.c.f.j.a(com.google.firebase:firebase-messaging@@20.0.0:1)
at com.google.firebase.messaging.n.close(com.google.firebase:firebase-messaging@@20.0.0:1)
at com.google.firebase.messaging.h.a(com.google.firebase:firebase-messaging@@20.0.0:23)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.0.0:42)
at com.google.firebase.messaging.i.run(com.google.firebase:firebase-messaging@@20.0.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at com.google.android.gms.common.util.q.b.run(:2)
at java.lang.Thread.run(Thread.java:818)
I am also getting this issue on different devices.

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okio.Segment.limit' on a null object reference
at com.android.okio.OkBuffer.write + 574(OkBuffer.java:574)
at com.android.okio.OkBuffer.read + 610(OkBuffer.java:610)
at com.android.okio.RealBufferedSource.read + 53(RealBufferedSource.java:53)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.read + 446(HttpConnection.java:446)
at com.android.okhttp.internal.Util.skipAll + 227(Util.java:227)
at com.android.okhttp.internal.http.HttpConnection.discard + 216(HttpConnection.java:216)
at com.android.okhttp.internal.http.HttpConnection$FixedLengthSource.close + 468(HttpConnection.java:468)
at com.android.okio.RealBufferedSource.close + 198(RealBufferedSource.java:198)
at com.android.okio.RealBufferedSource$1.close + 181(RealBufferedSource.java:181)
at f.c.a.b.b.g.j.a + 1(com.google.firebase:firebase-messaging@@20.0.0:1)
at com.google.firebase.messaging.l.close + 1(com.google.firebase:firebase-messaging@@20.0.0:1)
at com.google.firebase.messaging.f.a + 22(com.google.firebase:firebase-messaging@@20.0.0:22)
at com.google.firebase.messaging.FirebaseMessagingService.zzc + 42(com.google.firebase:firebase-messaging@@20.0.0:42)
at com.google.firebase.messaging.g.run + 2(com.google.firebase:firebase-messaging@@20.0.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker + 1115(ThreadPoolExecutor.java:1115)
at java.util.concurrent.ThreadPoolExecutor$Worker.run + 590(ThreadPoolExecutor.java:590)
at com.google.android.gms.common.util.q.d.run + 2(:2)
at java.lang.Thread.run + 818(Thread.java:818)
Same problem
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
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:55)
at com.android.okhttp.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:393)
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$FixedLengthSource.close(Http1xStream.java:410)
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.zzk.zza(com.google.firebase:firebase-messaging@@20.0.0:4)
at com.google.firebase.messaging.zzj.close(com.google.firebase:firebase-messaging@@20.0.0:38)
at com.google.firebase.messaging.zzd.zza(com.google.firebase:firebase-messaging@@20.0.0:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.0.0:60)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.0.0:2)
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(:6)
at java.lang.Thread.run(Thread.java:764)
Coming from firebase messaging
Same problem;
Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'int com.android.okhttp.okio.Segment.limit' on a null object reference
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:170)
at com.android.okhttp.internal.Util.discard(Util.java:152)
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(com.google.firebase:firebase-messaging@@20.0.0:4)
at com.google.firebase.messaging.zzj.close(com.google.firebase:firebase-messaging@@20.0.0:38)
at com.google.firebase.messaging.zzd.zza(com.google.firebase:firebase-messaging@@20.0.0:51)
at com.google.firebase.messaging.FirebaseMessagingService.zzc(com.google.firebase:firebase-messaging@@20.0.0:60)
at com.google.firebase.messaging.zze.run(com.google.firebase:firebase-messaging@@20.0.0:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.android.gms.common.util.concurrent.zza.run(:6)
at java.lang.Thread.run(Thread.java:764)
Hey all, this has been fixed in the firebase-messaging SDK version 20.1.0 which was released recently, you can find the release notes here:
https://firebase.google.com/support/release-notes/android#messaging_v20-1-0
Thank you all for reporting and for your patience waiting for the fix! If you upgrade to the new SDK and still see this crash, please file a new issue on this GitHub repo.
Most helpful comment
This is really sad that so many users faced the same issue but still we don’t have a solution. Firebase team should do something in future updates. For time being i will not use the images.