{"record":{"id":"0152eb35967d9de6","repo":"MuntashirAkon/AppManager","slug":"path-does-not-exist","errorCode":null,"errorMessage":"Path  does not exist.","messagePattern":"Path  does not exist\\.","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/self/filecache/FileCache.java","lineNumber":78,"sourceCode":"    public void close() {\n        mClosed = true;\n        if (mSessionOnly) {\n            deleteAll();\n        }\n    }\n\n    @Override\n    protected void finalize() {\n        if (!mClosed) {\n            close();\n        }\n    }\n\n    @NonNull\n    public File getCachedFile(@NonNull Path source) throws IOException {\n        if (!source.exists()) {\n            // No need for cache if the path is non-existent\n            throw new FileNotFoundException(\"Path \" + source + \" does not exist.\");\n        }\n        File tempFile = mFileCacheMap.get(source);\n        if (tempFile == null || !tempFile.exists()) {\n            String extension = source.getExtension();\n            tempFile = File.createTempFile(source.getName() + \"_\", \".\" + (extension != null ? extension : \"tmp\"), mCacheDir);\n            mFileCacheMap.put(source, tempFile);\n        } else if (source.lastModified() > 0 && source.lastModified() < tempFile.lastModified()) {\n            return tempFile;\n        }\n        IoUtils.copy(source, Paths.get(tempFile));\n        return tempFile;\n    }\n\n    @NonNull\n    public File getCachedFile(@NonNull InputStream is, @Nullable String extension) throws IOException {\n        File tempFile = File.createTempFile(\"file_\", \".\" + (extension != null ? extension : \"tmp\"), mCacheDir);\n        mFileCache.add(tempFile);\n        try (OutputStream os = new FileOutputStream(tempFile)) {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/self/filecache/FileCache.java#L60-L96","documentation":"FileCache.getCachedFile throws FileNotFoundException when the given Path does not exist on the filesystem. The cache layer intentionally refuses to cache a non-existent source instead of silently creating an empty temp file. Callers must ensure the source path is valid before requesting a cached copy.","triggerScenarios":"Calling getCachedFile(Path) with a path that was deleted, never created, is on unmounted storage, or whose string form is empty/malformed so exists() returns false.","commonSituations":"Caching a file picked from SAF whose underlying document was removed; referencing an app data file after the app was cleared; path on external storage that is not mounted; race where another process deletes the file between listing and caching.","solutions":["Check source.exists() before calling getCachedFile and handle the missing file gracefully","Re-resolve or re-fetch the source path (e.g. re-query the SAF URI) since it may be stale","Verify storage volume is mounted (Environment.getExternalStorageState) before use","Wrap in try-catch FileNotFoundException and fall back to skipping the cache"],"exampleFix":"// before\nFile cached = fileCache.getCachedFile(sourcePath);\n// after\nif (sourcePath.exists()) {\n    File cached = fileCache.getCachedFile(sourcePath);\n} else {\n    // re-resolve the URI or skip caching\n}","handlingStrategy":"validation","validationCode":"if (source == null || !source.exists()) {\n    throw new FileNotFoundException(\"Path \" + source + \" does not exist.\");\n}","typeGuard":"static boolean isReadableFile(Path p) {\n    return p != null && p.exists() && p.isFile() && p.canRead();\n}","tryCatchPattern":"try {\n    File cached = cache.getCachedFile(source);\n} catch (FileNotFoundException e) {\n    // re-resolve source or skip caching\n}","preventionTips":["Always check source.exists() before requesting a cached file","Re-resolve SAF/document URIs close to the point of use","Check storage mount state before touching external paths","Handle TOCTOU: the file may vanish between check and use, so keep the try-catch"],"tags":["io","file-cache","android"],"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-23T08:17:48.524Z"}