Obteniendo NullPointerException: intente obtener la longitud de la matriz nula en Parcelable cuando intente leer una matriz de bytes en Android

Tengo una clase que implementa Parcelable. Todos mis valores se establecen correctamente a través del método writeToParcel, pero al leer dentro del constructor tengo un problema con una matriz de bytes que arroja NullPointerException:

public final class Product implements Parcelable {

    private Integer ID;
    private byte[] image;

    // Constructors
    public Product(){}

    public Product(Parcel source) {
        this.ID = source.readInt();
        source.readByteArray(this.image);
    }

    public int describeContents() {
        return this.hashCode();
    }

    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(this.ID);
        dest.writeByteArray(this.image);
    }

    public static final Parcelable.Creator<Product> CREATOR
            = new Parcelable.Creator<Product>() {
        public Product createFromParcel(Parcel in) {
            return new Product(in);
        }

        public Product[] newArray(int size) {
            return new Product[size];
        }
    };

    // Getters
    public Integer getID () {
        return this.ID;
    }

    public byte[] getImage() {
        return this.image;
    }

    // Setters
    public void setID (Integer id) { this.ID = id; }

    public void setImage(byte[] image) {
        this.image = image;
    }
}

así que he notado que la matriz de bytes no se inicializa antes de leerla y luego la inicializo modificando el constructor de esta manera:

    public Product(Parcel source) {
        this.ID = source.readInt();

        this.image = new byte[source.readInt()];
        source.readByteArray(this.image);
    }

y ahora recibo este otro error:

Caused by: java.lang.NullPointerException: Attempt to get length of null array

Entonces, ¿qué estoy haciendo mal?

De todos modos, no entiendo por qué tengo que inicializar la matriz de bytes cuando se lee como writeToParcel se llama primero y asignar un valor a la matriz de bytes, por lo que al leer solo quiero obtener el valor escrito por WriteToParcel del constructor ... ¿Podría alguien explicarme? yo también esto, por favor? Tal vez no entiendo el objeto Parcelable en absoluto ...

RESUELTO POR:

En escritura ...

    dest.writeInt(this.image.length);
    dest.writeByteArray(this.image);

En lectura ...

    this.image = new byte[source.readInt()];
    source.readByteArray(this.image);

Respuestas a la pregunta(0)

Su respuesta a la pregunta