{"record":{"id":"4f7fcf261855e70b","repo":"MuntashirAkon/AppManager","slug":"parcelable-protocol-requires-a-parcelable-creator-object","errorCode":null,"errorMessage":"Parcelable protocol requires a Parcelable.Creator object called CREATOR on class \" + name","messagePattern":"Parcelable protocol requires a Parcelable\\.Creator object called CREATOR on class \" \\+ name","errorType":"exception","errorClass":"BadParcelableException","httpStatus":null,"severity":"error","filePath":"libcore/io/src/main/java/aosp/android/content/pm/ParcelUtils.java","lineNumber":74,"sourceCode":"                    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);\n                } catch (NoSuchFieldException e) {\n                    throw new BadParcelableException(\"Parcelable protocol requires a \"\n                            + \"Parcelable.Creator object called \"\n                            + \"CREATOR on class \" + name);\n                }\n                if (creator == null) {\n                    throw new BadParcelableException(\"Parcelable protocol requires a \"","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/aosp/android/content/pm/ParcelUtils.java#L56-L92","documentation":"ParcelUtils.readParcelableCreator requires the class's CREATOR field to be of a type assignable to Parcelable.Creator. If the field exists and is static but has some other type, BadParcelableException is thrown before Field.get() to avoid initializing the class.","triggerScenarios":"Reading a Parcelable whose CREATOR field is declared as a non-Creator type (e.g. a custom factory interface, Parcelable.Creator's raw generic in an incompatible hierarchy, or a field named CREATOR of an unrelated type).","commonSituations":"Refactoring where CREATOR's type was changed; classes with a constant named CREATOR that isn't a Creator; copying parcel-read helpers across unrelated classes.","solutions":["Change the CREATOR field's declared type to Parcelable.Creator<T>","Rename any unrelated constant that shadows the CREATOR convention","Confirm the class name in the parcel refers to the intended Parcelable class"],"exampleFix":"// before\npublic static final MyCustomFactory CREATOR = new MyCustomFactory();\n// after\npublic static final Parcelable.Creator<MyData> CREATOR = new Parcelable.Creator<MyData>() {...};","handlingStrategy":"validation","validationCode":"try {\n    Class<?> c = Class.forName(name, false, loader);\n    Class<?> t = c.getField(\"CREATOR\").getType();\n    if (!Parcelable.Creator.class.isAssignableFrom(t)) throw new IllegalStateException(\"CREATOR wrong type\");\n} catch (ReflectiveOperationException e) { /* handle */ }","typeGuard":null,"tryCatchPattern":"try {\n    T p = ParcelUtils.readParcelable(parcel, loader);\n} catch (BadParcelableException e) {\n    Log.e(TAG, \"CREATOR type invalid on class\", e);\n}","preventionTips":["Declare CREATOR with the exact type Parcelable.Creator<T>","Don't name non-Creator constants \"CREATOR\"","Use IDE Parcelable templates to generate correct CREATORs"],"tags":["parcel","android","reflection","serialization"],"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"}