{"record":{"id":"650adfaf2b2c5fc6","repo":"MuntashirAkon/AppManager","slug":"parcelable-protocol-requires-the-creator-object-to-be-static","errorCode":null,"errorMessage":"Parcelable protocol requires the CREATOR object to be static on class \" + name","messagePattern":"Parcelable protocol requires the CREATOR object to be static on class \" \\+ name","errorType":"exception","errorClass":"BadParcelableException","httpStatus":null,"severity":"error","filePath":"libcore/io/src/main/java/aosp/android/content/pm/ParcelUtils.java","lineNumber":67,"sourceCode":"                mCreators.put(loader, map);\n            }\n            creator = map.get(name);\n            if (creator == null) {\n                try {\n                    // If loader == null, explicitly emulate Class.forName(String) \"caller\n                    // classloader\" behavior.\n                    ClassLoader parcelableClassLoader = (loader == null ? from.getClass().getClassLoader() : loader);\n                    // Avoid initializing the Parcelable class until we know it implements\n                    // Parcelable and has the necessary CREATOR field.\n                    Class<?> parcelableClass = Class.forName(name, false /* initialize */,\n                            parcelableClassLoader);\n                    if (!Parcelable.class.isAssignableFrom(parcelableClass)) {\n                        throw new BadParcelableException(\"Parcelable protocol requires that the \"\n                                + \"class implements Parcelable\");\n                    }\n                    Field f = parcelableClass.getField(\"CREATOR\");\n                    if ((f.getModifiers() & Modifier.STATIC) == 0) {\n                        throw new BadParcelableException(\"Parcelable protocol requires \"\n                                + \"the CREATOR object to be static on class \" + name);\n                    }\n                    Class<?> creatorType = f.getType();\n                    if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {\n                        // Fail before calling Field.get(), not after, to avoid initializing\n                        // parcelableClass unnecessarily.\n                        throw new BadParcelableException(\"Parcelable protocol requires a \"\n                                + \"Parcelable.Creator object called \"\n                                + \"CREATOR on class \" + name);\n                    }\n                    creator = (Parcelable.Creator<?>) f.get(null);\n                } catch (IllegalAccessException e) {\n                    Log.e(TAG, \"Illegal access when unmarshalling: \" + name, e);\n                    throw new BadParcelableException(\n                            \"IllegalAccessException when unmarshalling: \" + name);\n                } catch (ClassNotFoundException e) {\n                    Log.e(TAG, \"Class not found when unmarshalling: \" + name, e);\n                    throw new BadParcelableException(\"ClassNotFoundException when unmarshalling: \" + name);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/aosp/android/content/pm/ParcelUtils.java#L49-L85","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Declare CREATOR as public static final Parcelable.Creator<T>","If using a non-static inner class, make the class static or move CREATOR appropriately","Recheck the exact class named in the parcel — a subclass may have the bad CREATOR"],"exampleFix":"// before\npublic final Parcelable.Creator<MyData> CREATOR = new Creator<MyData>() {...};\n// after\npublic static final Parcelable.Creator<MyData> CREATOR = new Creator<MyData>() {...};","handlingStrategy":"validation","validationCode":"try {\n    Field f = cls.getField(\"CREATOR\");\n    if (!Modifier.isStatic(f.getModifiers())) throw new IllegalStateException(\"CREATOR must be static\");\n} catch (NoSuchFieldException e) { /* not parcelable-ready */ }","typeGuard":null,"tryCatchPattern":"try {\n    T p = ParcelUtils.readParcelable(parcel, loader);\n} catch (BadParcelableException e) {\n    Log.e(TAG, \"Malformed Parcelable: \" + e.getMessage(), e);\n}","preventionTips":["Always declare CREATOR as public static final","Enable lint checks for Parcelable implementations","Review CREATOR when converting classes to Parcelable"],"tags":["parcel","android","reflection","static"],"backgroundTag":"incompatible-source-type","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}