{"record":{"id":"12b42f14edb3916e","repo":"MuntashirAkon/AppManager","slug":"there-were-some-keystore-items-but-they-couldn-t-be-cached","errorCode":null,"errorMessage":"There were some KeyStore items but they couldn't be cached before taking a backup.","messagePattern":"There were some KeyStore items but they couldn't be cached before taking a backup\\.","errorType":"exception","errorClass":"BackupException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java","lineNumber":425,"sourceCode":"        } catch (FileNotFoundException ignore) {\n        }\n        // Store the KeyStore files\n        Path cachePath = Paths.get(FileUtils.getCachePath());\n        List<String> cachedKeyStoreFileNames = new ArrayList<>();\n        List<String> keyStoreFilters = new ArrayList<>();\n        for (String keyStoreFileName : KeyStoreUtils.getKeyStoreFiles(mApplicationInfo.uid, mUserId)) {\n            try {\n                String newFileName = Utils.replaceOnce(keyStoreFileName, String.valueOf(mApplicationInfo.uid),\n                        String.valueOf(KEYSTORE_PLACEHOLDER));\n                IoUtils.copy(keyStorePath.findFile(keyStoreFileName), cachePath.findOrCreateFile(newFileName, null));\n                cachedKeyStoreFileNames.add(newFileName);\n                keyStoreFilters.add(Pattern.quote(newFileName));\n            } catch (Throwable e) {\n                throw new BackupException(\"Could not cache \" + keyStoreFileName, e);\n            }\n        }\n        if (cachedKeyStoreFileNames.isEmpty()) {\n            throw new BackupException(\"There were some KeyStore items but they couldn't be cached before taking a backup.\");\n        }\n        String keyStorePrefix = KEYSTORE_PREFIX + getExt(mMetadata.info.tarType);\n        Path[] backedUpKeyStoreFiles;\n        try {\n            backedUpKeyStoreFiles = TarUtils.create(mMetadata.info.tarType, cachePath, mBackupItem.getUnencryptedBackupPath(), keyStorePrefix,\n                            keyStoreFilters.toArray(new String[0]), null, null, false)\n                    .toArray(new Path[0]);\n        } catch (Throwable th) {\n            throw new BackupException(\"Could not backup KeyStore item.\", th);\n        }\n        // Remove cache\n        for (String name : cachedKeyStoreFileNames) {\n            try {\n                cachePath.findFile(name).delete();\n            } catch (FileNotFoundException ignore) {\n            }\n        }\n        try {","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/backup/BackupOp.java#L407-L443","documentation":"After attempting to cache all KeyStore files, backupKeyStore() verifies at least one was actually cached. If the list is empty despite keystore items being requested, it throws this BackupException, aborting rather than writing an empty keystore backup.","triggerScenarios":"Every IoUtils.copy attempt failed silently-range (each threw and was rethrown) — actually if any throws it aborts earlier; this fires when the keystore item contained no matching files at all (findFile/filter yielded nothing) so cachedKeyStoreFileNames stayed empty.","commonSituations":"Keystore directory empty or path resolution returned no files for the uid; filter pattern mismatch after uid→placeholder renaming; app has a keystore backup flag set but no keystore entries exist for the uid.","solutions":["Verify the app/uid actually owns keystore files at the expected path","Skip the keystore backup item when no keystore files exist instead of requesting it","Log the keystore directory listing before caching to confirm files are discovered","Check filename pattern/uid replacement logic if files exist but are filtered out"],"exampleFix":"// before\nif (cachedKeyStoreFileNames.isEmpty()) {\n    throw new BackupException(\"There were some KeyStore items but they couldn't be cached before taking a backup.\");\n}\n// after\nif (cachedKeyStoreFileNames.isEmpty()) {\n    Log.w(TAG, \"No keystore files found for uid \" + mApplicationInfo.uid + \"; skipping keystore backup\");\n    return;\n}","handlingStrategy":"validation","validationCode":"if (keystoreItemRequested && listKeystoreFiles(uid).isEmpty()) {\n    Log.w(TAG, \"no keystore files for uid \" + uid + \"; drop keystore item\");\n    return;\n}","typeGuard":"static boolean hasCachedFiles(List<String> cached) {\n    return cached != null && !cached.isEmpty();\n}","tryCatchPattern":"try {\n    runBackup();\n} catch (BackupException e) {\n    if (e.getMessage().contains(\"couldn't be cached\")) degradeToBackupWithoutKeystore();\n    else throw e;\n}","preventionTips":["Only request keystore item when keystore files exist for the uid","Log directory listing before caching","Treat empty keystore as a skip, not an error"],"tags":["backup","keystore","empty-result"],"backgroundTag":"empty-result-set","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"}