Skip to content

Object is not parceled correctly if it has a field of an array of its own type #56

@unparalleled

Description

@unparalleled

Consider this example class:

public class Example {
    private Example[] array;
}

After generating the parcelable code, we get:

public class Example implements Parcelable {

    private Example[] array;


    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeParcelable(this.array, flags);
    }

    public Example() {
    }

    protected Example(Parcel in) {
        this.array = in.readParcelable(Example[].class.getClassLoader());
    }

    public static final Parcelable.Creator<Example> CREATOR = new Parcelable.Creator<Example>() {
        @Override
        public Example createFromParcel(Parcel source) {
            return new Example(source);
        }

        @Override
        public Example[] newArray(int size) {
            return new Example[size];
        }
    };
}

writeParcelable should be writeTypedArray
readParcelable should be createTypedArray

This issue seams to be in ParcelableSerializerFactory.getSerializer() where the psiType of the class we're currently working on has not yet implemented the Parcelable interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions