{"record":{"id":"06bcb4bb59d7ef99","repo":"MuntashirAkon/AppManager","slug":"could-not-read-backup-metadata-possibly-due-to-a-malformed","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/RestoreOp.java","lineNumber":134,"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(\"Failed to get checksums.\", e);\n        }\n        // Verify metadata\n        if (!requestedFlags.skipSignatureCheck()) {\n            try {\n                verifyMetadata();\n            } catch (BackupException e) {\n                mBackupItem.cleanup();\n                throw e;\n            }\n        }\n        // Check user handle","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java#L116-L152","documentation":"RestoreOp reads metadata.json via mBackupItem.getMetadata(mBackupInfo); an IOException is wrapped as BackupException saying the backup metadata JSON is likely malformed. This occurs after crypto setup succeeds, so the metadata file exists but cannot be parsed/decrypted readably.","triggerScenarios":"getMetadata throws IOException because metadata.json is corrupt, truncated, empty, or was not decrypted properly (wrong crypto producing garbage).","commonSituations":"metadata.json lost during partial backup copy; file corrupted by editing or transfer; decryption succeeded at file level but content is invalid due to version mismatch between backup and app formats.","solutions":["Verify metadata.json inside the (decrypted) backup is valid JSON and non-empty","Re-copy the backup directory completely; do not edit metadata.json manually","Confirm the app version supports the metadata format of the backup (v2/v5 schema differences)","Re-create the backup if the metadata file is unrecoverable"],"exampleFix":"// before\nmBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;\n// after\nFile metaFile = new File(backupDir, \"metadata.json\");\nif (!metaFile.exists() || metaFile.length() == 0) {\n    throw new BackupException(\"metadata.json is missing or empty; backup copy is incomplete.\");\n}\nmBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;","handlingStrategy":"validation","validationCode":"File meta = new File(backupDir, \"metadata.json\");\nif (!meta.isFile() || meta.length() == 0) throw new BackupException(\"metadata.json missing/empty in \" + backupDir);","typeGuard":"boolean hasMetadata(Path dir) { return dir.resolve(\"metadata.json\").toFile().isFile(); }","tryCatchPattern":"try { new RestoreOp(...); } catch (BackupException e) { if (e.getMessage().contains(\"Could not read backup metadata\")) { validateJsonOrRecreateBackup(); } throw e; }","preventionTips":["Never edit metadata.json manually","Include metadata.json when migrating backups between devices","Confirm format-version compatibility (v2 vs v5) before restoring"],"tags":["json","metadata","backup","restore","android"],"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-14T16:17:12.679Z"}