{"record":{"id":"319d1f372d83a5be","repo":"MuntashirAkon/AppManager","slug":"enoent","errorCode":"ENOENT","errorMessage":"${file}: ${errnoMessage}","messagePattern":"\\$\\{file\\}: \\$\\{errnoMessage\\}","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"libcore/io/src/main/java/io/github/muntashirakon/io/NIOFactory.java","lineNumber":58,"sourceCode":"            @NonNull\n            @Override\n            public ExtendedFile getFile(@Nullable String parent, @NonNull String child) {\n                return new LocalFile(parent, child);\n            }\n\n            @SuppressLint(\"NewApi\")\n            @NonNull\n            @Override\n            public FileChannel openChannel(@NonNull File file, int mode) throws IOException {\n                if (Build.VERSION.SDK_INT >= 26) {\n                    return FileChannel.open(file.toPath(), FileUtils.modeToOptions(mode));\n                } else {\n                    FileUtils.Flag f = FileUtils.modeToFlag(mode);\n                    if (f.write) {\n                        if (!f.create) {\n                            if (!file.exists()) {\n                                ErrnoException e = new ErrnoException(\"open\", OsConstants.ENOENT);\n                                throw new FileNotFoundException(file + \": \" + e.getMessage());\n                            }\n                        }\n                        if (f.append) {\n                            return new FileOutputStream(file, true).getChannel();\n                        }\n                        if (!f.read && f.truncate) {\n                            return new FileOutputStream(file, false).getChannel();\n                        }\n\n                        // Unfortunately, there is no way to create a write-only channel\n                        // without truncating. Forced to open rw RAF in all cases.\n                        FileChannel ch = new RandomAccessFile(file, \"rw\").getChannel();\n                        if (f.truncate) {\n                            ch.truncate(0);\n                        }\n                        return ch;\n                    } else {\n                        return new FileInputStream(file).getChannel();","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/io/src/main/java/io/github/muntashirakon/io/NIOFactory.java#L40-L76","documentation":"NIOFactory.openChannel() resolves an open mode via FileUtils.modeToFlag and maps it to a Java stream channel. For write modes without O_CREATE ('c'/'e' semantics), the library checks file existence first; if missing, it synthesizes ErrnoException(\"open\", ENOENT) and throws FileNotFoundException(\"${file}: ${errnoMessage}\"). This mimics POSIX open(2) failing with ENOENT when O_CREAT was not supplied.","triggerScenarios":"Opening a channel with a mode that requests write+truncate but not create (e.g. \"wt\", \"w\" without 'c') on a path that does not exist; the file was deleted between an existence check and open; a typo'd path passed to a non-creating write open.","commonSituations":"Caller assumes open always creates the file but the mode string lacks the create flag; file removed by another process before open; wrong working directory/relative path used for remote file systems.","solutions":["Add the create flag ('c') to the mode string so missing files are created","Check file.exists() first and create it (or fix the path) before opening without create","Catch FileNotFoundException and either create the file or surface a clear path error"],"exampleFix":"// before\nFileChannel ch = NIOFactory.openChannel(file, \"wt\"); // FileNotFoundException if missing\n// after\nFileChannel ch = NIOFactory.openChannel(file, \"wct\"); // 'c' creates the file if missing","handlingStrategy":"validation","validationCode":"if (!file.exists() && !mode.contains(\"c\")) {\n    throw new FileNotFoundException(\"create flag missing for non-existent file: \" + file);\n}","typeGuard":null,"tryCatchPattern":"try { ch = NIOFactory.openChannel(file, mode); } catch (FileNotFoundException e) { /* create file or correct path, then retry */ }","preventionTips":["Include the create flag ('c') in write modes unless ENOENT is desired","Check file existence and path correctness before non-creating opens","Catch FileNotFoundException distinctly from other IOExceptions"],"tags":["filesystem","file-not-found","enoent","nio","open-flags"],"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-14T11:17:12.474Z"}