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

Forbid unparcelable types #7

Open
JakeWharton opened this issue Aug 27, 2014 · 3 comments
Open

Forbid unparcelable types #7

JakeWharton opened this issue Aug 27, 2014 · 3 comments

Comments

@JakeWharton
Copy link

I had an erroneous Object type in one of my classes which was being filled with a type that was not parcelable. Parcel's writeValue does take an Object but it's very specific about which types are allowed: https://developer.android.com/reference/android/os/Parcel.html#writeValue(java.lang.Object).

I want my build to fail if a type is used that does not meet these requirements.

@frankiesardo
Copy link
Owner

Makes sense. I'll patch it up

@frankiesardo
Copy link
Owner

It might be less straightforward than I though. The definition of writeValue is recursive.

That means you can have valid nested types such as List<List<List<Foo>>> and at each step the generic type of the collection should be extracted and passed again to the checker method. I'm still trying to figure out if there's a non-awkward way to extract wildcard types out of a TypeMirror, especially if said type is hidden as in class Bar implements List<List<List<Foo>>>. The only solution seems to involve calling typeUtils.directSupertypes(), filter those that are still the same collection type, and repeat until declaredType.getTypeArguments() is not empty. Not the end of the world but I wish there was a safer way. And there might be edge cases that I haven't considered.
I'm open to suggestions if somebody knows a better way.

(If only somebody would embrace the challenge of writing a properly documented library that abstracts over all these compile types weirdness I guess we would see many more APT libraries released).

@macr00
Copy link

macr00 commented Oct 24, 2015

Hi guys, I'm sure this is an issue in my code and not with the library, but somewhat related. I have a UserParcel object annotated with@AutoParcel implementing Parcelable with a static reference to my User object (not parcelable), which also contains a custom 'Image' object (also not parcelable) but contains parcelable variables.

I am running into this error - the log shows it to crash at the 'if (v instanceof IBinder)' condition in the android Parcel class:

java.lang.RuntimeException: Parcel: unable to marshal value User{...
at android.os.Parcel.writeValue(Parcel.java:1343)

public final void writeValue(Object v) {
...
else if (v instanceof IBinder) {
writeInt(VAL_IBINDER);
writeStrongBinder((IBinder) v);
}

Any ideas where I'm going wrong?
Thanks in advance

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