mattprecious / telescope

A simple tool to allow easy bug report capturing within your app.
Apache License 2.0
1.18k stars 116 forks source link

Attempt to cast generated internal exception: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList #41

Open pranaypatel512 opened 8 years ago

pranaypatel512 commented 8 years ago

03-01 10:01:53.078 12936-12936/com.mattprecious.telescope.sample W/Bundle: Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a java.lang.String. The default value <null> was returned. 03-01 10:01:53.078 12936-12936/com.mattprecious.telescope.sample W/Bundle: Attempt to cast generated internal exception: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1067) at android.os.Bundle.getCharSequenceArrayList(Bundle.java:922) at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:5471) at android.content.Intent.migrateExtraStreamToClipData(Intent.java:8173) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1572) at android.app.Activity.startActivityForResult(Activity.java:3921) at android.app.Activity.startActivityForResult(Activity.java:3881) at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784) at android.app.Activity.startActivity(Activity.java:4208) at android.app.Activity.startActivity(Activity.java:4176) at com.mattprecious.telescope.EmailLens.onCapture(EmailLens.java:71) at com.mattprecious.telescope.TelescopeLayout$SaveScreenshotTask.onPostExecute(TelescopeLayout.java:582) at com.mattprecious.telescope.TelescopeLayout$SaveScreenshotTask.onPostExecute(TelescopeLayout.java:543) at android.os.AsyncTask.finish(AsyncTask.java:651) at android.os.AsyncTask.-wrap1(AsyncTask.java) at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

I am getting this error log here to long press with two finger: https://goo.gl/9uRTkz

NightlyNexus commented 8 years ago

This seems odd because the doc for Intent.EXTRA_TEXT clearly says a CharSequence should be expected. It looks like something something was expecting an ArrayList. Do you have info about the device this occurred on?

mattprecious commented 8 years ago

So it looks this code path is a thing in AOSP. I'm trying to figure out why I've never seen this happen before... I have a feeling a bunch of email apps are going to stop working if I start passing an array in...

NightlyNexus commented 8 years ago

I don't think it looks like AOSP at all. Somewhere, modified sample code or something is calling getCharSequenceArrayList(Intent.EXTRA_TEXT), and the call will just return null after failing the cast. Needs an explanation about how to reproduce; no sample code here does that.

mattprecious commented 8 years ago

Well, it is in AOSP: Activity.java#3930 > Instrumentation.java#1505 > Intent.java#8250

It looks like it'll fail the cast, log the warning, and return null. So there won't be any body in the email.

But I agree that we need more info about device and Android version and what not because I've never seen this happen on any device that I've used or people on my team have used. Something is different to get that code path to be executed.

rharter commented 8 years ago

I'm integrating this as well have have the same issue. Though, unlike what you might expect, The email does have a body.

I have a custom lens that simply adds a log file (written with my custom Timer.Tree), but that attachment isn't included. Here's the important bits from my custom Lens.

@Override protected Set<Uri> getAdditionalAttachments() {
  return Collections.singleton(logFile);
}

And the full log:

W/Bundle: Key android.intent.extra.TEXT expected ArrayList<CharSequence> but value was a java.lang.String.  The default value <null> was returned.
W/Bundle: Attempt to cast generated internal exception:
    java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
    at android.os.BaseBundle.getCharSequenceArrayList(BaseBundle.java:1067)
    at android.os.Bundle.getCharSequenceArrayList(Bundle.java:922)
    at android.content.Intent.getCharSequenceArrayListExtra(Intent.java:5547)
    at android.content.Intent.migrateExtraStreamToClipData(Intent.java:8247)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1505)
    at android.app.Activity.startActivityForResult(Activity.java:3930)
    at android.app.Activity.startActivityForResult(Activity.java:3890)
    at android.app.Activity.startActivity(Activity.java:4213)
    at android.app.Activity.startActivity(Activity.java:4181)
    at com.mattprecious.telescope.EmailLens.onCapture(EmailLens.java:71)
    ...

Seems to me like AOSP is trying to copy the attachments (Intent.EXTRA_STREAM) to the clip board, but is expecting them to be an ArrayList<CharSequence> instead of an ArrayList<Parcelable>.

And, of course, my device info:

Make: LGE
Model: Nexus 5X
Release: 6.0.1
API: 23
rharter commented 8 years ago

Hmm, notice how it's complaining about the EXTRA_TEXT field, not the EXTRA_STREAM.

I wonder if this is relevant from the Intent docs:

If using this approach, you still must supply the same data through the EXTRA_TEXT or EXTRA_STREAM fields described below for compatibility with old applications. If you don't set a ClipData, it will be copied there for you when calling startActivity(Intent).
rharter commented 8 years ago

Updating my Lens to send a FileProvider uri to the local log file, and adding Intent.FLAG_GRANT_READ_URI_PERMISSION to the intent solves the issue of the attachment missing (makes sense). The warning is still there, but I get the body of the email without issue (in Inbox).

mattprecious commented 8 years ago

I think your log file being omitted is a separate issue (though a good one). The warning is still being logged for you so it doesn't sound like that fixed anything.

rharter commented 8 years ago

You're correct. The missing log file was a different issue of mine. I haven't narrowed down the cause of the warning, but everything appears to be working as expected.

pranaypatel512 commented 8 years ago

While debugging app and also adding exception handling code as below, yet I am getting same exception: try { context.startActivity(intent); } catch (ClassCastException e) { e.printStackTrace(); } I found: ClassCastException warning in log when opening e-mail app with a body and multiple file attachments. Also found similer thread Android: ClassCastException on opening Email Chooser

swankjesse commented 7 years ago

I’m able to reproduce this reliably with my Nexus 5X / API 24 emulator on Telescope 2.1.

renanbandeira commented 7 years ago

I'm also able to reproduce this.

PembaTamang commented 1 year ago

Happening with me right now, any fixes guys ?

mattprecious commented 1 year ago

No fixes have been provided in this project as I still haven't experienced this and don't really understand why this is happening. If you're able to reproduce it, then please feel free to copy EmailLens into your project to make the type changes and report back here on whether it worked and didn't cause issues with other devices or email clients.