Tuesday, December 31, 2019

Parceling and unparceling is not necessarily deep cloning

Serializing something to a temporary buffer then deserializing it is often an easy way to duplicate an object that supports serialization. Today I was trying to make independent copies of a handful of different Parcelable classes, so I tried writing a general function to parcel them then read them back out. I ran into trouble with testing because my Robolectric shadows of IBinder classes the parcelables referred to contributed state that did not get written to the parcel. However, I realized another problem: parcels can transfer active IBinder objects. These will be reconstituted into proxies that call into the original object, foiling the plan of creating a deep, independent copy for an arbitrary Parcelable.

No comments:

Post a Comment