5

In analytics for our app we've noticed increased number of crashes for the getIntent().getExtras() calls. It's intermittent and we can't replicate that.

Crashes come in two flavours:

12  Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.os.Parcel.dataSize()' on a null object reference
13  at android.os.BaseBundle.<init>(BaseBundle.java:126)
14  at android.os.Bundle.<init>(Bundle.java:102)
15  at android.content.Intent.getExtras(Intent.java:5685)

and

12  Caused by: java.lang.IllegalArgumentException
13  at android.os.Parcel.nativeAppendFrom(Native Method)
14  at android.os.Parcel.appendFrom(Parcel.java:458)
15  at android.os.BaseBundle.<init>(BaseBundle.java:126)
16  at android.os.Bundle.<init>(Bundle.java:102)
17  at android.content.Intent.getExtras(Intent.java:5685)

Retrieving code is essentially as follows onResume() {... getIntent().getExtras() ...}. We check if the bundle in not null but it crashes before that.

We do pass a custom parcelable but extensive unit tests are passing for marshalling and unmarshalling that.

Interesting stats for those crashes are that it mostly happen for Android 6+ (72% of sessions recorded with 95% of crashes happen there). Also unexpectedly crash rarely happens on Samsung devices (73% of sessions recorded with only 10% crashes happen for that manufacturer).

This crash contibutes ~0.15% to the app crashrate with a rising trend (probably because increasing number or users on API23+).

Anyone encountered something similar or has a solution already?

fada21
  • 3,188
  • 1
  • 22
  • 21
  • 2
    Can you please post your Parcelable class? – MLProgrammer-CiM Dec 20 '16 at 14:23
  • 1
    "We do pass a custom parcelable but extensive unit tests are passing for marshalling and unmarshalling that" -- how exactly are you using this? Where is this `Intent` coming from? Particularly if it is an `Intent` being held by another process (e.g., `PendingIntent` to `AlarmManager`), [custom `Parcelable` classes are risky business](https://commonsware.com/blog/2016/07/22/be-careful-where-you-use-custom-parcelables.html). – CommonsWare Dec 20 '16 at 14:34
  • Hey @CommonsWare, I've just done reading your article googled out minutes ago and saw your comment ;). The reply was a blast. Answering your question: it's neither PendingIntent nor AlarmManager, it's one Activity passing an intent to the other when the app is in the foreground. I know as I've seen recorded session with this crash. Your advice looks promising anyway, thanks. I think I'll try it first. – fada21 Dec 20 '16 at 14:49
  • @MLProgrammer-CiM https://gist.github.com/fada21/7e9d2b6a2b54143004eb54808ce78db1 – fada21 Dec 20 '16 at 14:53
  • 1
    "it's one Activity passing an intent to the other when the app is in the foreground" -- I will be dismayed if that is unsafe for a custom `Parcelable` (and that class itself looks fine, based on a glance at your gist). FWIW, [this sample project](https://github.com/commonsguy/cw-omnibus/tree/master/Parcelable/Marshall) illustrates the technique for manually converting a `Parcelable` to/from a `byte[]`. – CommonsWare Dec 20 '16 at 14:56
  • Is it possible that this happens if activity A launches activity B, then the user leaves the app, the process gets killed and then user returns to B? It might help trying to test that and see if it happens (more frequently) under these conditions... "I know as I've seen recorded session with this crash." - have you got a video or full logs of that session? – Pedro Loureiro Dec 20 '16 at 21:25
  • @PedroLoureiro the video records that I've watched shows that the app is not killed and the activity (standard launch mode, no flags to set on Intent) crashes on start not on return to itself. Unfortunately I don't have full logs, just the crash logs + video. – fada21 Dec 20 '16 at 22:16

1 Answers1

0

Late update but better than never. Crashes went away. Solution I used can be found here: How to marshall and unmarshall a Parcelable to a byte array with help of Parcel?

To be honest I've removed some unnecessary parcelling and unparcelling from our app which might have also helped but I think the former solution is the relevant one.

fada21
  • 3,188
  • 1
  • 22
  • 21