{"record":{"id":"aa9d2db82353cfa1","repo":"MuntashirAkon/AppManager","slug":"restore-is-requested-without-any-flags","errorCode":null,"errorMessage":"Restore is requested without any flags.","messagePattern":"Restore is requested without any flags\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java","lineNumber":100,"sourceCode":"            progressHandler.setProgressTextInterface(ProgressHandler.PROGRESS_PERCENT);\n            progressHandler.postUpdate(max, 0f);\n        }\n        try (BackupOp backupOp = new BackupOp(options.packageName, options.flags, backupItem, options.userId)) {\n            backupOp.runBackup(progressHandler);\n            BackupUtils.putBackupToDbAndBroadcast(ContextUtils.getContext(), backupOp.getMetadata());\n        }\n    }\n\n    /**\n     * Restore a single backup for a given package belonging to the given package\n     */\n    public void restore(@NonNull RestoreOpOptions options, @Nullable ProgressHandler progressHandler)\n            throws BackupException {\n        if (options.packageName.equals(\"android\")) {\n            throw new BackupException(\"Android System (android) cannot be restored.\");\n        }\n        if (options.flags.isEmpty()) {\n            throw new BackupException(\"Restore is requested without any flags.\");\n        }\n        BackupItems.BackupItem backupItem;\n        try {\n            if (options.relativeDir != null) {\n                backupItem = BackupItems.findBackupItem(options.relativeDir);\n            } else {\n                // Use base backup\n                Backup baseBackup = BackupUtils.retrieveBaseBackupFromDb(options.userId, options.packageName);\n                if (baseBackup != null) {\n                    backupItem = baseBackup.getItem();\n                } else {\n                    throw new BackupException(\"No base backup found.\");\n                }\n            }\n        } catch (IOException e) {\n            throw new BackupException(\"Could not get backup files.\", e);\n        }\n        if (progressHandler != null) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java#L82-L118","documentation":"BackupManager.restore() requires at least one backup flag (e.g. source, data, permissions) in RestoreOpOptions.flags. An empty flag set means nothing to restore, so the method refuses to proceed with a BackupException. This is an upfront argument-validation error.","triggerScenarios":"Constructing RestoreOpOptions with flags left empty/null (default value) and calling restore(), restoreBackups(), or the testRestoreV4* helpers.","commonSituations":"Programmatically building restore options from user preferences where no checkbox was selected; forgetting to copy flag bitmasks when adapting sample code; deserializing options from storage where the flags field defaulted to 0.","solutions":["Set the desired flags on RestoreOpOptions before calling restore(), e.g. backup flags for APK/data.","If the caller should restore everything, pass the full flag set used by the UI defaults.","Validate flags non-empty at the call site and surface a user-facing 'nothing selected' message instead of invoking restore.","Catch BackupException to report the configuration problem."],"exampleFix":"// before\nRestoreOpOptions options = new RestoreOpOptions(pkg, userId); // flags empty\n// after\nRestoreOpOptions options = new RestoreOpOptions(pkg, userId,\n    BackupFlags.FLAG_APP_SOURCE | BackupFlags.FLAG_APP_DATA);","handlingStrategy":"validation","validationCode":"if (options.flags == null || options.flags.isEmpty()) {\n    throw new IllegalArgumentException(\"Restore flags must not be empty\");\n}","typeGuard":"boolean hasRestoreFlags(RestoreOpOptions o) { return o.flags != null && !o.flags.isEmpty(); }","tryCatchPattern":"try {\n    manager.restore(options, progress);\n} catch (BackupException e) {\n    if (e.getMessage().contains(\"without any flags\")) { /* prompt user to select flags */ }\n}","preventionTips":["Always populate flags from explicit user selection","Assert non-empty flags in unit tests before restore","Default to source+data flags when building options programmatically"],"tags":["android","backup","restore","flags","validation"],"backgroundTag":"missing-required-flag","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"}