{"record":{"id":"197e1d2987bddf34","repo":"MuntashirAkon/AppManager","slug":"rules-backup-is-requested-but-encountered-an-error-during","errorCode":null,"errorMessage":"Rules backup is requested but encountered an error during fetching rules.","messagePattern":"Rules backup is requested but encountered an error during fetching rules\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":590,"sourceCode":"            mChecksum.add(miscFile.getName(), DigestUtils.getHexDigest(mMetadata.info.checksumAlgo, miscFile));\n        } catch (IOException | IndexOutOfBoundsException e) {\n            throw new BackupException(\"Couldn't get misc.am.tsv for generating checksum\", e);\n        }\n    }\n\n    private void backupRules() throws BackupException {\n        try {\n            Path rulesFile = mBackupItem.getRulesFile();\n            try (OutputStream outputStream = rulesFile.openOutputStream();\n                 ComponentsBlocker cb = ComponentsBlocker.getInstance(mPackageName, mUserId)) {\n                ComponentUtils.storeRules(outputStream, cb.getAll(), true);\n            }\n            if (!rulesFile.exists()) return;\n            rulesFile = mBackupItem.encrypt(new Path[]{rulesFile})[0];\n            // Store checksum\n            mChecksum.add(rulesFile.getName(), DigestUtils.getHexDigest(mMetadata.info.checksumAlgo, rulesFile));\n        } catch (IOException | IndexOutOfBoundsException e) {\n            throw new BackupException(\"Rules backup is requested but encountered an error during fetching rules.\", e);\n        }\n    }\n}\n","sourceCodeStart":572,"sourceCodeEnd":594,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L572-L594","documentation":"backupRules() fetches the pseudo-rules file (rules.am.tsv via getRulesFile) and encrypts/checksums it. Any IOException or IndexOutOfBoundsException during fetch/encrypt is wrapped in this BackupException indicating the requested rules backup failed.","triggerScenarios":"mBackupItem.getRulesFile() throws IOException (backup dir not accessible) or encrypt(new Path[]{rulesFile})[0] throws IndexOutOfBoundsException (empty encryption output) or checksum read fails — all only when rules backup is requested via flags.","commonSituations":"Rules backup flag enabled but no rules exist for the package; destination directory missing; encrypted output filter excluding the rules file; crypto metadata absent.","solutions":["Check chained cause to distinguish fetch (IOException) vs encrypt (IndexOutOfBounds) failures","If no rules exist for the package, disable the rules backup flag instead of failing","Verify the backup directory is writable and crypto metadata is valid","Return early when getRulesFile() yields a non-existent file (code already checks rulesFile.exists())"],"exampleFix":"// before\nrulesFile = mBackupItem.encrypt(new Path[]{rulesFile})[0];\n// after\nPath[] enc = mBackupItem.encrypt(new Path[]{rulesFile});\nif (enc.length == 0) { Log.w(TAG, \"No encrypted output for rules file\"); return; }\nrulesFile = enc[0];","handlingStrategy":"try-catch","validationCode":"if (rulesBackupRequested && !hasRulesForPackage(pkg)) {\n    Log.i(TAG, \"no rules; skipping rules backup\");\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    backupRules();\n} catch (BackupException e) {\n    Log.e(TAG, \"rules backup failed\", e.getCause());\n    // continue without rules or abort per policy\n}","preventionTips":["Enable rules backup flag only when rules exist","Guard encrypt()[0] indexing","Ensure destination dir writable before fetching rules"],"tags":["backup","rules","encryption"],"backgroundTag":"file-not-found","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"}