{"record":{"id":"e01a5e42e8c928fb","repo":"microg/GmsCore","slug":"expected-object-header-got-0x-integer-tohexstr","errorCode":null,"errorMessage":"Expected object header. Got 0x\" + Integer.toHexString(header)","messagePattern":"Expected object header\\. Got 0x\" \\+ Integer\\.toHexString\\(header\\)","errorType":"exception","errorClass":"ReadException","httpStatus":null,"severity":"error","filePath":"play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelReader.java","lineNumber":62,"sourceCode":"    }\n\n    private static void readExpectedSize(Parcel parcel, int header, int expectedSize) {\n        int i = readSize(parcel, header);\n        if (i != expectedSize)\n            throw new ReadException(\"Expected size \" + expectedSize + \" got \" + i + \" (0x\" + Integer.toHexString(i) + \")\", parcel);\n    }\n\n    @Deprecated\n    public static int readStart(Parcel parcel) {\n        return readObjectHeader(parcel);\n    }\n\n    public static int readObjectHeader(Parcel parcel) {\n        int header = readHeader(parcel);\n        int size = readSize(parcel, header);\n        int start = parcel.dataPosition();\n        if (getFieldId(header) != SafeParcelable.SAFE_PARCEL_OBJECT_MAGIC)\n            throw new ReadException(\"Expected object header. Got 0x\" + Integer.toHexString(header), parcel);\n        int end = start + size;\n        if ((end < start) || (end > parcel.dataSize()))\n            throw new ReadException(\"Size read is invalid start=\" + start + \" end=\" + end, parcel);\n        return end;\n    }\n\n    public static int readInt(Parcel parcel, int header) {\n        readExpectedSize(parcel, header, 4);\n        return parcel.readInt();\n    }\n\n    public static byte readByte(Parcel parcel, int header) {\n        readExpectedSize(parcel, header, 4);\n        return (byte) parcel.readInt();\n    }\n\n    public static short readShort(Parcel parcel, int header) {\n        readExpectedSize(parcel, header, 4);","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-basement/src/main/java/com/google/android/gms/common/internal/safeparcel/SafeParcelReader.java#L44-L80","documentation":"SafeParcelReader.readObjectHeader() (used by readStart) verifies that the header it reads is an object-start marker (SAFE_PARCEL_OBJECT_MAGIC) and throws ReadException 'Expected object header. Got 0x...' when the field id in the header does not match. It also validates the size/end position against the Parcel bounds. This indicates the stream is misaligned or was not written by SafeParcelable serialization.","triggerScenarios":"Calling SafeParcelReader.readStart(parcel) on a Parcel whose next object is not a SafeParcel object header, e.g. a plain Bundle, wrong dataPosition, or extra/missing fields causing misalignment.","commonSituations":"Reading a Parcel from a different starting offset; parsing Parcels written by non-SafeParcelable code; version skew between writer and reader field counts.","solutions":["Verify the Parcel was written by SafeParcelable serialization and read from position 0","Ensure writer and reader classes/versions match","Check that no fields were consumed before readStart()","Catch ReadException and fall back to alternative parsing"],"exampleFix":"// before\nint end = SafeParcelReader.readStart(parcel); // parcel position misaligned\n// after\ntry {\n    int end = SafeParcelReader.readStart(parcel);\n} catch (SafeParcelReader.ReadException e) {\n    throw new IllegalArgumentException(\"Not a SafeParcelable parcel\", e);\n}","handlingStrategy":"try-catch","validationCode":"// ensure parcel.dataPosition() == 0 and data written by SafeParcelable before readStart()","typeGuard":null,"tryCatchPattern":"try { int end = SafeParcelReader.readStart(parcel); } catch (SafeParcelReader.ReadException e) { handleMalformedHeader(e); }","preventionTips":["Read from dataPosition 0; don't consume fields before readStart","Match reader/writer versions exactly","Wrap unmarshalling in ReadException handling"],"tags":["parcel","deserialization","safeparcel"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}