auto-value-parcel icon indicating copy to clipboard operation
auto-value-parcel copied to clipboard

Check if objects inside lists can be written into parcel

Open bejibx opened this issue 7 years ago • 3 comments

This is kind of question/feature request.

In short question is: can we somehow check if values contained inside our List members can be written into parcel?

So imagine we have some value class:

@AutoValue
abstract class ExampleClass implements Parcelable {

    abstract int intMember();
    
    @NonNull
    abstract String stringMember();
}

Nothing special. If we add some non-parcelable member to our ExampleClass we'll got error message at compile time which is super cool. Unfortunately this is not true if we'll add List<NonParcelableClass>:

@AutoValue
abstract class ExampleClass implements Parcelable {

    abstract int intMember();
    
    @NonNull
    abstract String stringMember();

    @NonNull
    abstract List<NonParcelableClass> listMember();
}

@AutoValue
abstract class NonParcelableClass {

    abstract int intMember();
    
    @NonNull
    abstract String stringMember();
}

In this case we'll get exception only at runtime, which sucks. I'm not familiar with code generation, so I don't know if we can check generic type parameters or not, but if we can, I think preventing those type of bugs at compile time is super-duper-cool.

bejibx avatar May 19 '17 12:05 bejibx

It's supposed to do this already... I'll adapt your code to a test case later this week. Also feel free to try and create a PR with a failing test case if you want to beat me to it.

JakeWharton avatar May 25 '17 04:05 JakeWharton

Also got bitten by this last week.

vanniktech avatar May 25 '17 09:05 vanniktech

Confirmed we're only checking raw types. Will PR a fix

ZacSweers avatar Jan 19 '20 06:01 ZacSweers