{"record":{"id":"441ecfb6679ab39a","repo":"MuntashirAkon/AppManager","slug":"backup-with-name-mbackupnames-0-doesn-t-exist","errorCode":null,"errorMessage":"Backup with name ${mBackupNames[0]} doesn't exist.","messagePattern":"Backup with name (.+?) doesn't exist\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/batchops/struct/BatchBackupOptions.java","lineNumber":68,"sourceCode":"        }\n        return new BackupOpOptions(packageName, userId, mFlags, backupName, !customBackup);\n    }\n\n    public RestoreOpOptions getRestoreOpOptions(@NonNull String packageName, @UserIdInt int userId) {\n        // For restore operation, backup names (v4) and relative dirs are only set for single\n        // package backups. In all other cases, it only uses base backups.\n        String relativeDir;\n        if (mRelativeDirs != null && mRelativeDirs.length > 0) {\n            relativeDir = mRelativeDirs[0];\n        } else {\n            if (mBackupNames == null || mBackupNames.length == 0) {\n                // Base backup\n                relativeDir = null;\n            } else {\n                // Generate relative directories\n                Backup backup = BackupUtils.retrieveLatestBackupFromDb(userId, mBackupNames[0], packageName);\n                if (backup == null) {\n                    throw new IllegalArgumentException(\"Backup with name \" + mBackupNames[0] + \" doesn't exist.\");\n                }\n                relativeDir = backup.relativeDir;\n            }\n        }\n        return new RestoreOpOptions(packageName, userId, relativeDir, mFlags);\n    }\n\n    public DeleteOpOptions getDeleteOpOptions(@NonNull String packageName, @UserIdInt int userId) {\n        // For delete operation, backup names (v4) and relative dirs are only set for single\n        // package backups. In all other cases, it only uses base backups.\n        String[] relativeDirs;\n        if (mRelativeDirs != null) {\n            relativeDirs = mRelativeDirs;\n        } else {\n            if (mBackupNames == null || mBackupNames.length == 0) {\n                // Base backup\n                relativeDirs = null;\n            } else {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/batchops/struct/BatchBackupOptions.java#L50-L86","documentation":"BatchBackupOptions.getRestoreOpOptions() resolves the first backup name to a latest Backup record via BackupUtils.retrieveLatestBackupFromDb(userId, mBackupNames[0], packageName); if the DB returns null, it throws IllegalArgumentException. It means no backup matching the given name exists for that package/user, so no relative directory can be resolved for the restore operation.","triggerScenarios":"Calling restoreBackups with a BatchBackupOptions whose first backup name has no matching record in App Manager's backup database for the given package and user ID.","commonSituations":"Typo in the backup name; backup deleted or never created; querying under a different user ID than the one the backup was made under; stale database after backups were moved between devices.","solutions":["List existing backups (BackupUtils) and use an exact, existing backup name.","Create the backup with the given name before restoring.","Verify the userId passed matches the user the backup belongs to.","Rebuild/refresh App Manager's backup database if backups exist on disk but not in the DB."],"exampleFix":"// before\nnew BatchBackupOptions(\"mybackup\", null, flags).getRestoreOpOptions(pkg, userId);\n// after\nString name = BackupUtils.getBackupNames().contains(\"mybackup\") ? \"mybackup\"\n        : /* pick existing */ BackupUtils.getBackupNames().iterator().next();\nnew BatchBackupOptions(name, null, flags).getRestoreOpOptions(pkg, userId);","handlingStrategy":"validation","validationCode":"Backup b = BackupUtils.retrieveLatestBackupFromDb(userId, backupName, packageName);\nif (b == null) throw new IllegalArgumentException(\"No backup named '\" + backupName + \"' for \" + packageName + \" user \" + userId);","typeGuard":null,"tryCatchPattern":"try {\n    options.getRestoreOpOptions(pkg, userId);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"doesn't exist\")) {\n        // surface available backup names to the user\n    } else throw e;\n}","preventionTips":["Resolve backup names from BackupUtils listings instead of hardcoding strings.","Always pair name lookups with the same userId used in the op options.","Re-sync the backup DB after migrating backups between devices."],"tags":["android","backup","batch-operations","not-found"],"backgroundTag":"record-not-found","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}