{"record":{"id":"2d95f5d863a44d4c","repo":"MuntashirAkon/AppManager","slug":"could-not-read-backup-metadata-possibly-due-to-a-malformed-2d95f5","errorCode":null,"errorMessage":"Could not read backup metadata. Possibly due to a malformed json file.","messagePattern":"Could not read backup metadata\\. Possibly due to a malformed json file\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/VerifyOp.java","lineNumber":56,"sourceCode":"            mBackupItem.cleanup();\n            throw new BackupException(\"Could not read backup info. Possibly due to a malformed json file.\", e);\n        }\n        // Setup crypto\n        if (!CryptoUtils.isAvailable(mBackupInfo.crypto)) {\n            mBackupItem.cleanup();\n            throw new BackupException(\"Mode \" + mBackupInfo.crypto + \" is currently unavailable.\");\n        }\n        try {\n            mBackupItem.setCrypto(mBackupInfo.getCrypto());\n        } catch (CryptoException e) {\n            mBackupItem.cleanup();\n            throw new BackupException(\"Could not get crypto \" + mBackupInfo.crypto, e);\n        }\n        try {\n            mBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;\n        } catch (IOException e) {\n            mBackupItem.cleanup();\n            throw new BackupException(\"Could not read backup metadata. Possibly due to a malformed json file.\", e);\n        }\n        // Get checksums\n        try {\n            mChecksum = mBackupItem.getChecksum();\n        } catch (Throwable e) {\n            mBackupItem.cleanup();\n            throw new BackupException(\"Could not get checksums.\", e);\n        }\n        // Verify metadata\n        try {\n            verifyMetadata();\n        } catch (BackupException e) {\n            mBackupItem.cleanup();\n            throw e;\n        }\n    }\n\n    @Override","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/VerifyOp.java#L38-L74","documentation":"VerifyOp reads the (decrypted) metadata file via mBackupItem.getMetadata(mBackupInfo). If parsing the metadata JSON throws IOException, cleanup() runs and this BackupException is thrown — the metadata file is absent, unreadable, or not valid JSON, mirroring error 153 but for the metadata file rather than backup.json.","triggerScenarios":"verify() on a backup where the encrypted metadata cannot be decrypted into valid JSON (wrong key silently producing garbage handled as IO failure), the metadata file is missing from the backup directory, or it was truncated in transfer.","commonSituations":"Partial backup copies, wrong decryption key yielding an undecryptable blob, backups moved between devices with interrupted file sync, or manually pruned backup directories.","solutions":["Re-copy the complete backup including the metadata file.","Confirm the crypto credentials are correct so metadata decrypts to valid JSON.","Recreate the backup from the source device if metadata is unrecoverable.","Validate the decrypted metadata with a JSON linter to spot structural corruption."],"exampleFix":"// before: metadata missing from copied backup dir\nbackup/\n  backup.json\n// after: full backup directory\nbackup/\n  backup.json\n  metadata.json.enc\n  ...","handlingStrategy":"validation","validationCode":"// Decrypt and JSON-validate metadata before verify\nbyte[] meta = decrypt(metadataFile); // with correct credentials\nnew JSONObject(new String(meta)); // throws early if garbage/invalid","typeGuard":null,"tryCatchPattern":"try {\n    new VerifyOp(backupItem).verify();\n} catch (BackupException e) {\n    if (e.getMessage().contains(\"Could not read backup metadata\")) {\n        // wrong key or missing/truncated metadata file: re-copy backup or fix credentials\n    }\n}","preventionTips":["Test decryption right after creating an encrypted backup.","Verify copied backups by listing and JSON-parsing every top-level file.","Keep source backups until a restore has fully succeeded on the destination."],"tags":["json","metadata","backup-verify","malformed-file"],"backgroundTag":"json-parse-error","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}