MuntashirAkon/AppManager · error · FileNotFoundException

ENOENT

ENOENT

Error message

${file}: ${errnoMessage}

What it means

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.

Source

Thrown at libcore/io/src/main/java/io/github/muntashirakon/io/NIOFactory.java:58

            @NonNull
            @Override
            public ExtendedFile getFile(@Nullable String parent, @NonNull String child) {
                return new LocalFile(parent, child);
            }

            @SuppressLint("NewApi")
            @NonNull
            @Override
            public FileChannel openChannel(@NonNull File file, int mode) throws IOException {
                if (Build.VERSION.SDK_INT >= 26) {
                    return FileChannel.open(file.toPath(), FileUtils.modeToOptions(mode));
                } else {
                    FileUtils.Flag f = FileUtils.modeToFlag(mode);
                    if (f.write) {
                        if (!f.create) {
                            if (!file.exists()) {
                                ErrnoException e = new ErrnoException("open", OsConstants.ENOENT);
                                throw new FileNotFoundException(file + ": " + e.getMessage());
                            }
                        }
                        if (f.append) {
                            return new FileOutputStream(file, true).getChannel();
                        }
                        if (!f.read && f.truncate) {
                            return new FileOutputStream(file, false).getChannel();
                        }

                        // Unfortunately, there is no way to create a write-only channel
                        // without truncating. Forced to open rw RAF in all cases.
                        FileChannel ch = new RandomAccessFile(file, "rw").getChannel();
                        if (f.truncate) {
                            ch.truncate(0);
                        }
                        return ch;
                    } else {
                        return new FileInputStream(file).getChannel();

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Add the create flag ('c') to the mode string so missing files are created
  2. Check file.exists() first and create it (or fix the path) before opening without create
  3. Catch FileNotFoundException and either create the file or surface a clear path error

Example fix

// before
FileChannel ch = NIOFactory.openChannel(file, "wt"); // FileNotFoundException if missing
// after
FileChannel ch = NIOFactory.openChannel(file, "wct"); // 'c' creates the file if missing
Defensive patterns

Strategy: validation

Validate before calling

if (!file.exists() && !mode.contains("c")) {
    throw new FileNotFoundException("create flag missing for non-existent file: " + file);
}

Try / catch

try { ch = NIOFactory.openChannel(file, mode); } catch (FileNotFoundException e) { /* create file or correct path, then retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/319d1f372d83a5be. Report an issue: GitHub.