Error retrieving a Serializable from a Bundle with a ClassLoader set

Last Updated:

  1. eborix13

    eborix13 New Member This Topic's Starter

    Apr 9, 2009
    Likes Received:
    I'm trying to retrieve a Serializable object (Bundle.getSerializable(String key)) from a Bundle I've constructed using the Bundle(ClassLoader loader) constructor. While doing this I get a ClassNotFoundException.

    The comment of the Bundle constructor states: "Constructs a new, empty Bundle that uses a specific ClassLoader for instantiating Parcelable and Serializable objects". I've looked through the source code of the Bundle class and I noticed that retrieving a Serializable object executes the Bundle.unparcel() method which finally comes down to the Parcel.readValue(ClassLoader loader). All good so far. But the readValue method doesn't use the ClassLoader to read Serializable objects:

    Code (Text):
    1.  case VAL_SERIALIZABLE:
    2.             return readSerializable();
    as it does when reading Parcelable objects:

    Code (Text):
    1.  case VAL_PARCELABLE:
    2.             return readParcelable(loader);
    This seems to be the cause of the error I get.

    Is the comment of the Bundle(ClassLoader loader) constructor correct and the reading of the Serializable object is a bug? Or is the code in the Parcel.readValue() method correct and the comment is wrong? The comment of the Bundle.setClassLoader(ClassLoader loader) method is a bit more vague in relation to Serializable objects: "Changes the ClassLoader this Bundle uses when instantiating objects", although it basically sets the same ClassLoader that is set in the constructor. So, are Serializable objects retrieved using the specified ClassLoader or not?


Share This Page