MuntashirAkon/AppManager · error · BackupException

Could not read backup metadata. Possibly due to a malformed

Error message

Could not read backup metadata. Possibly due to a malformed json file.

What it means

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.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/backup/RestoreOp.java:134

            mBackupItem.cleanup();
            throw new BackupException("Could not read backup info. Possibly due to a malformed json file.", e);
        }
        // Setup crypto
        if (!CryptoUtils.isAvailable(mBackupInfo.crypto)) {
            mBackupItem.cleanup();
            throw new BackupException("Mode " + mBackupInfo.crypto + " is currently unavailable.");
        }
        try {
            mBackupItem.setCrypto(mBackupInfo.getCrypto());
        } catch (CryptoException e) {
            mBackupItem.cleanup();
            throw new BackupException("Could not get crypto " + mBackupInfo.crypto, e);
        }
        try {
            mBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;
        } catch (IOException e) {
            mBackupItem.cleanup();
            throw new BackupException("Could not read backup metadata. Possibly due to a malformed json file.", e);
        }
        // Get checksums
        try {
            mChecksum = mBackupItem.getChecksum();
        } catch (Throwable e) {
            mBackupItem.cleanup();
            throw new BackupException("Failed to get checksums.", e);
        }
        // Verify metadata
        if (!requestedFlags.skipSignatureCheck()) {
            try {
                verifyMetadata();
            } catch (BackupException e) {
                mBackupItem.cleanup();
                throw e;
            }
        }
        // Check user handle

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Verify metadata.json inside the (decrypted) backup is valid JSON and non-empty
  2. Re-copy the backup directory completely; do not edit metadata.json manually
  3. Confirm the app version supports the metadata format of the backup (v2/v5 schema differences)
  4. Re-create the backup if the metadata file is unrecoverable

Example fix

// before
mBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;
// after
File metaFile = new File(backupDir, "metadata.json");
if (!metaFile.exists() || metaFile.length() == 0) {
    throw new BackupException("metadata.json is missing or empty; backup copy is incomplete.");
}
mBackupMetadata = mBackupItem.getMetadata(mBackupInfo).metadata;
Defensive patterns

Strategy: validation

Validate before calling

File meta = new File(backupDir, "metadata.json");
if (!meta.isFile() || meta.length() == 0) throw new BackupException("metadata.json missing/empty in " + backupDir);

Type guard

boolean hasMetadata(Path dir) { return dir.resolve("metadata.json").toFile().isFile(); }

Try / catch

try { new RestoreOp(...); } catch (BackupException e) { if (e.getMessage().contains("Could not read backup metadata")) { validateJsonOrRecreateBackup(); } throw e; }

Prevention

When it happens

Trigger: getMetadata throws IOException because metadata.json is corrupt, truncated, empty, or was not decrypted properly (wrong crypto producing garbage).

Common situations: 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.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/06bcb4bb59d7ef99. Report an issue: GitHub.