MuntashirAkon/AppManager · error · BadParcelableException

Parcelable protocol requires the CREATOR object to be static

Error message

Parcelable protocol requires the CREATOR object to be static on class " + name

What it means

ParcelUtils.readParcelableCreator reflects on the named class's CREATOR field and requires it to be static per the Parcelable protocol. A non-static CREATOR field triggers BadParcelableException with the class name.

Source

Thrown at libcore/io/src/main/java/aosp/android/content/pm/ParcelUtils.java:67

                mCreators.put(loader, map);
            }
            creator = map.get(name);
            if (creator == null) {
                try {
                    // If loader == null, explicitly emulate Class.forName(String) "caller
                    // classloader" behavior.
                    ClassLoader parcelableClassLoader = (loader == null ? from.getClass().getClassLoader() : loader);
                    // Avoid initializing the Parcelable class until we know it implements
                    // Parcelable and has the necessary CREATOR field.
                    Class<?> parcelableClass = Class.forName(name, false /* initialize */,
                            parcelableClassLoader);
                    if (!Parcelable.class.isAssignableFrom(parcelableClass)) {
                        throw new BadParcelableException("Parcelable protocol requires that the "
                                + "class implements Parcelable");
                    }
                    Field f = parcelableClass.getField("CREATOR");
                    if ((f.getModifiers() & Modifier.STATIC) == 0) {
                        throw new BadParcelableException("Parcelable protocol requires "
                                + "the CREATOR object to be static on class " + name);
                    }
                    Class<?> creatorType = f.getType();
                    if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {
                        // Fail before calling Field.get(), not after, to avoid initializing
                        // parcelableClass unnecessarily.
                        throw new BadParcelableException("Parcelable protocol requires a "
                                + "Parcelable.Creator object called "
                                + "CREATOR on class " + name);
                    }
                    creator = (Parcelable.Creator<?>) f.get(null);
                } catch (IllegalAccessException e) {
                    Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
                    throw new BadParcelableException(
                            "IllegalAccessException when unmarshalling: " + name);
                } catch (ClassNotFoundException e) {
                    Log.e(TAG, "Class not found when unmarshalling: " + name, e);
                    throw new BadParcelableException("ClassNotFoundException when unmarshalling: " + name);

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Declare CREATOR as public static final Parcelable.Creator<T>
  2. If using a non-static inner class, make the class static or move CREATOR appropriately
  3. Recheck the exact class named in the parcel — a subclass may have the bad CREATOR

Example fix

// before
public final Parcelable.Creator<MyData> CREATOR = new Creator<MyData>() {...};
// after
public static final Parcelable.Creator<MyData> CREATOR = new Creator<MyData>() {...};
Defensive patterns

Strategy: validation

Validate before calling

try {
    Field f = cls.getField("CREATOR");
    if (!Modifier.isStatic(f.getModifiers())) throw new IllegalStateException("CREATOR must be static");
} catch (NoSuchFieldException e) { /* not parcelable-ready */ }

Try / catch

try {
    T p = ParcelUtils.readParcelable(parcel, loader);
} catch (BadParcelableException e) {
    Log.e(TAG, "Malformed Parcelable: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: A class implements Parcelable but declares its CREATOR as a non-static (instance or inner-class) field, and an instance of that class name is read from a Parcel via readParcelable/readParcelableCreator.

Common situations: Copy-paste mistakes where CREATOR was declared inside a non-static inner class or forgot the static keyword; code converted from Java serializable patterns; Lombok/kotlin conversions dropping static.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/650adfaf2b2c5fc6. Report an issue: GitHub.