termux/termux-app · warning · FileNotFoundException

not found

Error message

 not found

What it means

Thrown by getFileForDocId when the File constructed from the document id does not exist (File.exists() returns false). This is the standard 'document not found' signal for a DocumentsProvider: SAF clients expect FileNotFoundException when referencing a deleted or never-existed document.

Source

Thrown at app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java:212

        return documentId.startsWith(parentDocumentId);
    }

    /**
     * Get the document id given a file. This document id must be consistent across time as other
     * applications may save the ID and use it to reference documents later.
     * <p/>
     * The reverse of @{link #getFileForDocId}.
     */
    private static String getDocIdForFile(File file) {
        return file.getAbsolutePath();
    }

    /**
     * Get the file given a document id (the reverse of {@link #getDocIdForFile(File)}).
     */
    private static File getFileForDocId(String docId) throws FileNotFoundException {
        final File f = new File(docId);
        if (!f.exists()) throw new FileNotFoundException(f.getAbsolutePath() + " not found");
        return f;
    }

    private static String getMimeType(File file) {
        if (file.isDirectory()) {
            return Document.MIME_TYPE_DIR;
        } else {
            final String name = file.getName();
            final int lastDot = name.lastIndexOf('.');
            if (lastDot >= 0) {
                final String extension = name.substring(lastDot + 1).toLowerCase();
                final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
                if (mime != null) return mime;
            }
            return "application/octet-stream";
        }
    }

View on GitHub (pinned to 3df69d1da1)

Solutions

  1. Treat FileNotFoundException as 'gone' and refresh/remove the stale reference in the client.
  2. Before operating on a persisted docId, re-query the provider to confirm existence.
  3. Ensure the storage holding the file is mounted.
  4. Avoid caching document ids across sessions without re-validation.
Defensive patterns

Strategy: validation

Validate before calling

File file = new File(docId);
if (!file.exists()) {
    // refresh client state; do not call provider with stale id
    return;
}

Try / catch

try {
    return provider.openDocument(uri, mode, signal);
} catch (FileNotFoundException e) {
    // refresh document tree; the id is stale
    refreshDocumentList();
    throw e;
}

Prevention

When it happens

Trigger: The client holds a stale document id referencing a file/dir that was deleted; the docId string is wrong or from a different root; the underlying storage was unmounted; a race where the file is deleted between query and open.

Common situations: SAF persistent URI permission points to a removed file; directory listing cached after deletion; user manually deleted the file outside the provider.

Related errors


AI-assisted analysis of termux/termux-app@3df69d1da1 (2026-08-13). Data as JSON: /api/errors/9c081dca75c62b1e. Report an issue: GitHub.