{"record":{"id":"2e01652a9a956269","repo":"MuntashirAkon/AppManager","slug":"could-not-open-file-for-reading","errorCode":null,"errorMessage":"Could not open file for reading: ","messagePattern":"Could not open file for reading: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/io/PathImpl.java","lineNumber":1235,"sourceCode":"        String mode = \"w\" + (append ? \"a\" : \"t\");\n        OutputStream os = context.getContentResolver().openOutputStream(documentFile.getUri(), mode);\n        if (os == null) {\n            throw new IOException(\"Could not resolve Uri: \" + documentFile.getUri());\n        }\n        return os;\n    }\n\n    @NonNull\n    public InputStream openInputStream() throws IOException {\n        DocumentFile documentFile = resolveFileOrNull(this.documentFile);\n        if (documentFile == null) {\n            throw new IOException(this.documentFile.getUri() + \" is a directory\");\n        }\n        if (documentFile instanceof ExtendedRawDocumentFile) {\n            try {\n                return Objects.requireNonNull(getFile()).newInputStream();\n            } catch (IOException e) {\n                throw new IOException(\"Could not open file for reading: \" + documentFile.getUri(), e);\n            }\n        } else if (documentFile instanceof VirtualDocumentFile) {\n            return ((VirtualDocumentFile) documentFile).openInputStream();\n        }\n        try {\n            InputStream is = context.getContentResolver().openInputStream(documentFile.getUri());\n            if (is == null) {\n                throw new IOException(\"Could not resolve Uri: \" + documentFile.getUri());\n            }\n            return is;\n        } catch (SecurityException e) {\n            throw new IOException(e);\n        }\n    }\n\n    public FileChannel openFileChannel(int mode) throws IOException {\n        DocumentFile documentFile = resolveFileOrNull(this.documentFile);\n        if (documentFile == null) {","sourceCodeStart":1217,"sourceCodeEnd":1253,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/io/PathImpl.java#L1217-L1253","documentation":"Thrown by PathImpl.openInputStream() when opening an InputStream on an ExtendedRawDocumentFile-backed file fails. The underlying FileInputStream could not be created (e.g. the file disappeared, is unreadable, or the raw file handle is stale). The original IOException is chained as the cause.","triggerScenarios":"Calling Path.openInputStream() or Path.newInputStream() on a path whose resolved DocumentFile is an ExtendedRawDocumentFile, and File.newInputStream() throws IOException (file deleted between resolution and open, permission revoked, or corrupted raw file).","commonSituations":"Files deleted by another process between exists() check and open; storage unmounted; SELinux or root-fs restrictions blocking raw reads; reading files under /data via the extended raw layer without root privileges.","solutions":["Re-check path existence with Path.exists() and retry the open","Verify the app/root has read permission on the underlying raw file","Catch IOException around openInputStream and surface documentFile.getUri() for diagnosis","Check that storage volume is still mounted before opening"],"exampleFix":"// before\nInputStream is = path.openInputStream();\n// after\nInputStream is;\ntry {\n    is = path.openInputStream();\n} catch (IOException e) {\n    if (!path.exists()) throw new FileNotFoundException(path.getUri().toString());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (!path.exists()) throw new FileNotFoundException(path.getUri().toString());","typeGuard":"boolean isOpenable(Path p) { return p.exists() && p.isFile(); }","tryCatchPattern":"try { InputStream is = path.openInputStream(); ... } catch (IOException e) { throw new IOException(\"Failed to open \" + path.getUri(), e); }","preventionTips":["Re-check exists() immediately before opening","Do not cache Path objects across storage events (unmount, revoke)","Chain the cause exception when rethrowing for diagnostics"],"tags":["io","android","file-open-failed","storage"],"backgroundTag":"file-open-failed","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"}