From ac5a0828c14eea59f2ffda85432ad1977d3e1ce0 Mon Sep 17 00:00:00 2001 From: Paul Duffin Date: Mon, 3 Feb 2014 15:02:17 +0000 Subject: [PATCH] Improve Parcel's handling of non-primitive arrays Treat arrays other than actual Object arrays (i.e. those whose component type is actually Object) and the primitive arrays already handled specially by Parcel as Serializable's. Issue: 64583 Change-Id: I3ff797f3262e77e4de27f35709bceee5410d1ed4 --- core/java/android/os/Parcel.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/core/java/android/os/Parcel.java b/core/java/android/os/Parcel.java index 67160985b8497..347079045aada 100644 --- a/core/java/android/os/Parcel.java +++ b/core/java/android/os/Parcel.java @@ -1246,9 +1246,6 @@ public final class Parcel { } else if (v instanceof Parcelable[]) { writeInt(VAL_PARCELABLEARRAY); writeParcelableArray((Parcelable[]) v, 0); - } else if (v instanceof Object[]) { - writeInt(VAL_OBJECTARRAY); - writeArray((Object[]) v); } else if (v instanceof int[]) { writeInt(VAL_INTARRAY); writeIntArray((int[]) v); @@ -1258,12 +1255,20 @@ public final class Parcel { } else if (v instanceof Byte) { writeInt(VAL_BYTE); writeInt((Byte) v); - } else if (v instanceof Serializable) { - // Must be last - writeInt(VAL_SERIALIZABLE); - writeSerializable((Serializable) v); } else { - throw new RuntimeException("Parcel: unable to marshal value " + v); + Class clazz = v.getClass(); + if (clazz.isArray() && clazz.getComponentType() == Object.class) { + // Only pure Object[] are written here, Other arrays of non-primitive types are + // handled by serialization as this does not record the component type. + writeInt(VAL_OBJECTARRAY); + writeArray((Object[]) v); + } else if (v instanceof Serializable) { + // Must be last + writeInt(VAL_SERIALIZABLE); + writeSerializable((Serializable) v); + } else { + throw new RuntimeException("Parcel: unable to marshal value " + v); + } } }