{"record":{"id":"f4449c0cc2852af1","repo":"MuntashirAkon/AppManager","slug":"could-not-verify-rules-file-nfile-rulesfile-getname-nfound","errorCode":null,"errorMessage":"Could not verify rules file.\\nFile: \" + rulesFile.getName() + \"\\nFound: \" + checksum + \"\\nRequired: \" + mChecksum.get(rulesFile.getName())","messagePattern":"Could not verify rules file\\.\\\\nFile: \" \\+ rulesFile\\.getName\\(\\) \\+ \"\\\\nFound: \" \\+ checksum \\+ \"\\\\nRequired: \" \\+ mChecksum\\.get\\(rulesFile\\.getName\\(\\)\\)","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/VerifyOp.java","lineNumber":226,"sourceCode":"                    \"\\nRequired: \" + mChecksum.get(miscFile.getName()));\n        }\n    }\n\n    private void verifyRules() throws BackupException {\n        Path rulesFile;\n        try {\n            rulesFile = mBackupItem.getRulesFile();\n        } catch (IOException e) {\n            if (mBackupMetadata.hasRules) {\n                throw new BackupException(\"Rules file is missing.\", e);\n            } else {\n                // There are no rules, just skip\n                return;\n            }\n        }\n        String checksum = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, rulesFile);\n        if (!checksum.equals(mChecksum.get(rulesFile.getName()))) {\n            throw new BackupException(\"Could not verify rules file.\" +\n                    \"\\nFile: \" + rulesFile.getName() +\n                    \"\\nFound: \" + checksum +\n                    \"\\nRequired: \" + mChecksum.get(rulesFile.getName()));\n        }\n    }\n}","sourceCodeStart":208,"sourceCodeEnd":232,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/VerifyOp.java#L208-L232","documentation":"BackupException thrown by VerifyOp.verifyRules when the SHA-style hex digest of the restored backup rules file does not match the checksum recorded in the backup metadata (mChecksum). The library computes DigestUtils.getHexDigest with the backup's checksum algorithm and compares it against the stored value to prove the rules file was restored intact.","triggerScenarios":"Restoring a backup whose rules file (rules.json etc.) was modified, truncated, or re-encoded after the backup was taken, or restoring with a metadata file from a different backup so the expected checksum doesn't correspond to the actual file.","commonSituations":"Manually editing the rules file before restore; copying backup files between devices where one file got corrupted or replaced; restoring only part of a backup so the checksum map belongs to another rules version.","solutions":["Regenerate the backup so the rules file and its recorded checksum match","Do not modify the rules file between backup and restore","Verify the checksum manually with the algo in mBackupInfo.checksumAlgo to see which side is wrong","Replace the rules file with the original one from the same backup set"],"exampleFix":"// before\nString checksum = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, rulesFile);\nif (!checksum.equals(mChecksum.get(rulesFile.getName()))) {\n    throw new BackupException(\"Could not verify rules file.\" + ...);\n}\n// after\nString checksum = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, rulesFile);\nString required = mChecksum.get(rulesFile.getName());\nif (required == null || !checksum.equals(required)) {\n    Log.w(TAG, \"Checksum mismatch/absent for \" + rulesFile.getName() + \", regenerating rules from app state\");\n    return; // or re-run backup to refresh the recorded checksum\n}","handlingStrategy":"validation","validationCode":"String expected = mChecksum.get(rulesFile.getName());\nString actual = DigestUtils.getHexDigest(mBackupInfo.checksumAlgo, rulesFile);\nif (expected == null || !expected.equals(actual)) {\n    throw new IllegalStateException(\"Rules file checksum mismatch: \" + rulesFile.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    verifyOp.verifyRules(rulesFile);\n} catch (BackupException e) {\n    Log.e(TAG, \"Rules file failed verification; regenerate backup\", e);\n    recoverByRegeneratingRules();\n}","preventionTips":["Never edit backup files between backup and restore","Keep the metadata (.info/checksum) file together with the rules file","Verify checksums right after copying backups between devices","Regenerate backups after changing the rules schema"],"tags":["backup","checksum","integrity"],"backgroundTag":"checksum-mismatch","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"}