{"record":{"id":"df8503c308222d3e","repo":"MuntashirAkon/AppManager","slug":"could-not-create-backupitem","errorCode":null,"errorMessage":"Could not create BackupItem.","messagePattern":"Could not create BackupItem\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java","lineNumber":78,"sourceCode":"    }\n\n    public void backup(@NonNull BackupOpOptions options, @Nullable ProgressHandler progressHandler)\n            throws BackupException {\n        if (options.packageName.equals(\"android\")) {\n            throw new BackupException(\"Android System (android) cannot be backed up.\");\n        }\n        if (options.flags.isEmpty()) {\n            throw new BackupException(\"Backup is requested without any flags.\");\n        }\n        BackupItems.BackupItem backupItem;\n        try {\n            if (options.override) {\n                backupItem = BackupItems.findOrCreateBackupItem(options.userId, options.backupName, options.packageName);\n            } else {\n                backupItem = BackupItems.createBackupItemGracefully(options.userId, options.backupName, options.packageName);\n            }\n        } catch (IOException e) {\n            throw new BackupException(\"Could not create BackupItem.\", e);\n        }\n        if (progressHandler != null) {\n            int max = calculateMaxProgress(options.flags);\n            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\")) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupManager.java#L60-L96","documentation":"BackupManager.backup resolves/creates the on-disk BackupItem for the target package (findOrCreateBackupItem or createBackupItemGracefully). Any IOException from that step (unreadable/unwritable backup location, existing backup conflicts, etc.) is rethrown as BackupException with this message and the original cause attached.","triggerScenarios":"Calling BackupManager.backup where BackupItems.createBackupItemGracefully (no override) or findOrCreateBackupItem (override=true) throws IOException — e.g. the backup directory cannot be created or an existing backup cannot be opened.","commonSituations":"Unwritable or full storage, SAF permission revoked for the backup folder, corrupted existing backup metadata when overriding, invalid backup name characters.","solutions":["Read getCause() of the BackupException to find the underlying IOException and fix that root cause","Verify the backup directory is writable and has free space","Use override=true (or delete the existing backup) if a stale backup blocks creation","Choose a valid backup name (no illegal path characters)"],"exampleFix":"// before\ntry {\n    backupManager.backup(options, null);\n} catch (BackupException e) {\n    Log.e(TAG, \"backup failed\", e);\n}\n// after\ntry {\n    backupManager.backup(options, null);\n} catch (BackupException e) {\n    if (e.getCause() instanceof IOException) {\n        // e.g. re-grant SAF permissions or free space, then retry\n        Log.e(TAG, \"backup storage problem: \" + e.getCause().getMessage());\n    }\n}","handlingStrategy":"try-catch","validationCode":"// verify backup storage is usable before calling backup\nif (!backupRoot.exists() && !backupRoot.mkdirs()) { /* fix storage first */ }\nif (backupRoot.getFreeSpace() < minRequired) { /* free space */ }","typeGuard":null,"tryCatchPattern":"try {\n    backupManager.backup(options, progressHandler);\n} catch (BackupException e) {\n    Throwable cause = e.getCause(); // IOException from BackupItem creation\n    Log.e(TAG, \"BackupItem creation failed\", cause);\n    // fix storage/permissions/name, then retry\n}","preventionTips":["Always inspect getCause() on BackupException","Verify backup dir writability and free space before starting","Use valid backup names and decide override policy up front"],"tags":["android","backup","file-io","wrapped-exception"],"backgroundTag":"file-write-failed","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"}