{"record":{"id":"4b19452d3de7519f","repo":"MuntashirAkon/AppManager","slug":"invalid-backup-name","errorCode":null,"errorMessage":"Invalid backup name ","messagePattern":"Invalid backup name ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupUtils.java","lineNumber":122,"sourceCode":"    @Nullable\n    public static String getRealBackupName(int backupVersion, @Nullable String backupNameWithUserId) {\n        if (backupVersion >= 5) {\n            return backupNameWithUserId;\n        } else {\n            // v4 or earlier backup: {userid}[_{backup_name}]\n            if (backupNameWithUserId == null || TextUtils.isDigitsOnly(backupNameWithUserId)) {\n                // It's only a user ID\n                return null;\n            } else {\n                int firstUnderscore = backupNameWithUserId.indexOf('_');\n                if (firstUnderscore != -1) {\n                    // Found an underscore\n                    String userHandle = backupNameWithUserId.substring(0, firstUnderscore);\n                    if (TextUtils.isDigitsOnly(userHandle)) {\n                        return backupNameWithUserId.substring(firstUnderscore + 1);\n                    }\n                }\n                throw new IllegalArgumentException(\"Invalid backup name \" + backupNameWithUserId);\n            }\n        }\n    }\n\n    public static String getReadableTarType(@TarUtils.TarType String tarType) {\n        int i = ArrayUtils.indexOf(TAR_TYPES, tarType);\n        if (i == -1) {\n            return \"GZip\";\n        }\n        return TAR_TYPES_READABLE[i];\n    }\n\n    @WorkerThread\n    @NonNull\n    public static HashMap<String, Backup> storeAllAndGetLatestBackupMetadata() {\n        AppDb appDb = new AppDb();\n        HashMap<String, Backup> backupMetadata = new HashMap<>();\n        HashMap<String, List<BackupMetadataV5>> allBackupMetadata = getAllMetadata();","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupUtils.java#L104-L140","documentation":"getRealBackupName() parses a backup name that may carry a user-id suffix (name_userid). If the segment before the first underscore is not digits-only, the name is considered malformed and an IllegalArgumentException 'Invalid backup name <name>' is thrown.","triggerScenarios":"Calling getRealBackupName with a backup name containing an underscore whose prefix is not a numeric user handle (e.g. 'my_backup' or 'foo_1_bar' where prefix 'foo' is non-numeric) and no earlier branch matched.","commonSituations":"User-supplied backup names containing underscores in the backup name itself; restoring backups created by other tools with different naming conventions; typos when passing backup names on the CLI.","solutions":["Rename the backup so any underscore follows a numeric user id (e.g. '0_myapp'), or remove underscores from the name","Pass the backup name without a user-id suffix if a single user is targeted","Validate the backup name format before calling getRealBackupName"],"exampleFix":"// before\nString real = BackupUtils.getRealBackupName(\"my_backup\"); // throws\n// after\nString real = BackupUtils.getRealBackupName(\"0_my_backup\"); // user 0, name 'my_backup'","handlingStrategy":"validation","validationCode":"static void requireValidBackupName(String name) {\n    if (name == null || name.isEmpty()) throw new IllegalArgumentException(\"empty backup name\");\n    int us = name.indexOf('_');\n    if (us > 0 && !TextUtils.isDigitsOnly(name.substring(0, us)))\n        throw new IllegalArgumentException(\"name must be '<userid>_<name>' or contain no underscore\");\n}","typeGuard":"static boolean isValidBackupName(String name) {\n    if (name == null || name.isEmpty()) return false;\n    int us = name.indexOf('_');\n    return us <= 0 || TextUtils.isDigitsOnly(name.substring(0, us));\n}","tryCatchPattern":"try {\n    String real = BackupUtils.getRealBackupName(name);\n} catch (IllegalArgumentException e) {\n    Toast.makeText(ctx, \"Invalid backup name: \" + name, Toast.LENGTH_LONG).show();\n}","preventionTips":["Format backup names as '<userid>_<name>' when including user ids","Avoid underscores in raw backup names","Validate names from user input/CLI before calling"],"tags":["validation","argument","backup-name"],"backgroundTag":"invalid-argument-format","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}