{"record":{"id":"e99bd55ca023c023","repo":"MuntashirAkon/AppManager","slug":"couldn-t-get-misc-am-tsv-for-generating-checksum","errorCode":null,"errorMessage":"Couldn't get misc.am.tsv for generating checksum","messagePattern":"Couldn't get misc\\.am\\.tsv for generating checksum","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":574,"sourceCode":"            } catch (IOException e) {\n                // Ignore exception\n                Log.e(TAG, e);\n            }\n        }\n        // Backup freezeType\n        Integer freezeType = FreezeUtils.loadFreezeMethod(mPackageName);\n        if (freezeType != null) {\n            rules.setFreezeType(freezeType);\n        }\n        // Commit\n        rules.commitExternal(miscFile);\n        if (!miscFile.exists()) return;\n        try {\n            miscFile = mBackupItem.encrypt(new Path[]{miscFile})[0];\n            // Store checksum\n            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    }","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L556-L592","documentation":"At the end of backupExtras(), the misc.am.tsv file is encrypted and its checksum recorded. Failures (IOException or IndexOutOfBoundsException) in encrypt or checksum steps are wrapped in this BackupException even though the file itself was produced.","triggerScenarios":"mBackupItem.encrypt(new Path[]{miscFile}) throws IOException (crypto config/stream error) or returns an empty array causing [0] to throw IndexOutOfBoundsException; DigestUtils checksum read can also throw IOException.","commonSituations":"Encrypted backup requested without valid crypto metadata; encrypt() returned no files (filter mismatch on the misc file); file deleted between creation and encryption.","solutions":["Check the cause: IndexOutOfBoundsException means encrypt returned an empty array — inspect its filter logic","Verify crypto metadata is present when encryption is requested","Confirm miscFile exists before encrypting (the code checks exists() earlier; re-check if running async)","Regenerate the misc file by rerunning backupExtras if it was removed mid-flow"],"exampleFix":"// before\nmiscFile = mBackupItem.encrypt(new Path[]{miscFile})[0];\n// after\nPath[] enc = mBackupItem.encrypt(new Path[]{miscFile});\nif (enc.length == 0) { Log.w(TAG, \"Encryption produced no output for misc.am.tsv\"); return; }\nmiscFile = enc[0];","handlingStrategy":"try-catch","validationCode":"if (!miscFile.exists()) return;\nPath[] enc = mBackupItem.encrypt(new Path[]{miscFile});\nif (enc == null || enc.length == 0) { Log.w(TAG, \"encrypt produced nothing\"); return; }","typeGuard":"static Path firstOrNull(Path[] arr) {\n    return (arr == null || arr.length == 0) ? null : arr[0];\n}","tryCatchPattern":"try {\n    miscFile = mBackupItem.encrypt(new Path[]{miscFile})[0];\n    mChecksum.add(miscFile.getName(), DigestUtils.getHexDigest(...));\n} catch (IOException | IndexOutOfBoundsException e) {\n    Log.e(TAG, \"checksum stage failed for misc.am.tsv\", e);\n}","preventionTips":["Guard encrypt() output length before indexing [0]","Confirm crypto metadata exists when encryption enabled","Re-verify file existence right before encrypt/checksum"],"tags":["backup","encryption","checksum","indexoutofbounds"],"backgroundTag":"checksum-mismatch","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"}