Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android.os.BadParcelableException: ClassNotFoundException when unmarshalling #733

Open
plastiv opened this issue Sep 7, 2020 · 2 comments

Comments

@plastiv
Copy link

plastiv commented Sep 7, 2020

Description

Asserting on activity result extra from ActivityScenario results in exception. This was not the case with ActivityTestRule.

Steps to Reproduce

  1. Start "picker" activity with scenario = ActivityScenario.launch(intent)
  2. Simulate result_ok with included parcelable extra
  3. Assert on activity result intent extras (which triggers unmarshalling ClassNotFoundException exception) with
val activityResult = scenario.result!!
assertThat(activityResult, hasResultCode(RESULT_OK))
assertThat(activityResult, hasResultData(hasExtraWithKey(KEY_SELECTED_CITY)))

Expected Results

Assertion works

Actual Results

Exception similar to next one:

android.os.BadParcelableException: ClassNotFoundException when unmarshalling: my.package.ParcelableAutoCompleteCity
at android.os.Parcel.readParcelableCreator(Parcel.java:3042)
at android.os.Parcel.readParcelable(Parcel.java:2964)
at android.os.Parcel.readValue(Parcel.java:2866)
at android.os.Parcel.readArrayMapInternal(Parcel.java:3244)
at android.os.BaseBundle.initializeFromParcelLocked(BaseBundle.java:292)
at android.os.BaseBundle.unparcel(BaseBundle.java:236)
at android.os.BaseBundle.keySet(BaseBundle.java:562)
at androidx.test.espresso.intent.matcher.BundleMatchers$BundleMatcher.matchesSafely(BundleMatchers.java:47)
at androidx.test.espresso.intent.matcher.BundleMatchers$BundleMatcher.matchesSafely(BundleMatchers.java:35)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.intent.matcher.IntentMatchers$7.matchesSafely(IntentMatchers.java:215)
at androidx.test.espresso.intent.matcher.IntentMatchers$7.matchesSafely(IntentMatchers.java:206)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.contrib.ActivityResultMatchers$1.matchesSafely(ActivityResultMatchers.java:46)
at androidx.test.espresso.contrib.ActivityResultMatchers$1.matchesSafely(ActivityResultMatchers.java:37)
at org.hamcrest.TypeSafeMatcher.matches(TypeSafeMatcher.java:67)
at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:7)
at androidx.test.espresso.matcher.ViewMatchers.assertThat(ViewMatchers.java:5)

AndroidX Test and Android OS Versions

1.3.0 and sdk29

Link to a public git repo demonstrating the problem:

I need some guidance. I guess this repo should have already some tests which work on activity result verification. What are they? I would then extend them to include parcelable extra into activity result intent.

Current workaround

Set classloader explicitly before asserting result

val activityResult = scenario.result!!
activityResult.resultData.setExtrasClassLoader(this::class.java.classLoader)
assertThat(activityResult, hasResultCode(RESULT_OK))
assertThat(activityResult, hasResultData(hasExtraWithKey(KEY_SELECTED_CITY)))
@nick2525
Copy link

Yes, it is reproducible. Are there any deadlines for when it will be fixed?

@Chrn0924
Copy link

Can this be handled before the call?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants