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

Check if objects inside lists can be written into parcel #120

Open
bejibx opened this issue May 19, 2017 · 3 comments
Open

Check if objects inside lists can be written into parcel #120

bejibx opened this issue May 19, 2017 · 3 comments
Labels
Milestone

Comments

@bejibx
Copy link

bejibx commented May 19, 2017

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.

@JakeWharton
Copy link
Collaborator

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.

@vanniktech
Copy link
Contributor

Also got bitten by this last week.

@ZacSweers
Copy link
Collaborator

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

@ZacSweers ZacSweers added bug and removed enhancement labels Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants