Skip to content

Fix SAF/VFS path resolution crash by using checked IOException instead of unchecked NPE#1933

Open
cw2k wants to merge 2 commits intoMuntashirAkon:masterfrom
cw2k:patch-1
Open

Fix SAF/VFS path resolution crash by using checked IOException instead of unchecked NPE#1933
cw2k wants to merge 2 commits intoMuntashirAkon:masterfrom
cw2k:patch-1

Conversation

@cw2k
Copy link

@cw2k cw2k commented Mar 6, 2026

Reviewer Summary
On some file errors (e.g. invalid file name or invalid SAF/VFS path),
PathImpl now throws a checked IOException that is handled by the caller.
Previously these situations produced an unchecked NullPointerException,
which bypasses normal error handling and ultimately crashes the app.
This change fixes #1932 and aligns file‑related failures with the
expected checked‑exception model.

description
This PR fixes the crash described in issue #1932.

PathImpl previously relied on Objects.requireNonNull(...) in several
SAF and VFS resolution paths. When DocumentFile.fromTreeUri(),
fromSingleUri(), or findFile() returned null (e.g. invalid SAF URI,
missing permissions, or non-existing VFS path components), the code
threw an unchecked NullPointerException ( in short NPE ) , causing the app to crash.

These cases represent normal file-related failure conditions and should
be reported via a checked IOException rather than an unchecked NPE.

Changes included:

  • Added ExUtils.requireNonNullOrThrow(...) to provide safe null
    validation with caller-defined IOException.
  • Updated PathImpl to use this helper for SAF and VFS path resolution.
  • Ensures invalid paths now produce a proper IOException instead of
    crashing the app.

This aligns PathImpl with the expected error-handling model, improves
robustness, and prevents crashes when users enter invalid paths.

cw2k added 2 commits March 6, 2026 23:14
Add a new utility method `requireNonNullOrThrow(...)` to ExUtils.

This helper validates a nullable value and throws a caller‑provided
IOException when the value is null. It provides a safer and more explicit
alternative to `Objects.requireNonNull(...)`, which always throws a
NullPointerException and is therefore unsuitable for expected I/O error
conditions such as missing files or invalid VFS path components.

Usage example:
´´´´
import io.github.muntashirakon.AppManager.utils.ExUtils;
...
    DocFile = ExUtils.requireNonNullOrThrow(
            someObj.findFile(FileName),
            () -> new IOException("Invalid File")
    );
´´´´

This prepares the codebase for fixing VFS path resolution in PathImpl,
where null values must be treated as I/O errors rather than programming
errors.

Signed-off-by: cw2k <3834079+cw2k@users.noreply.github.com>
…-related failures

Replaced unsafe Objects.requireNonNull(...) calls in SAF and VFS path
resolution with ExUtils.requireNonNullOrThrow(...).

DocumentFile.fromTreeUri(), fromSingleUri(), and findFile() may return
null in normal file‑related failure cases. Previously this triggered an
unchecked NullPointerException, crashing the app. These conditions are
I/O failures, not programming errors, and should be reported via the
checked IOException type.

PathImpl now throws IOException for invalid URIs and missing VFS
components, improving robustness and aligning error handling with the
rest of the API.

Signed-off-by: cw2k <3834079+cw2k@users.noreply.github.com>
Copy link
Contributor

@Tharow Tharow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@MuntashirAkon
Copy link
Owner

Is this your own work? The description reads as if it was created using gen AI. We have strict policy of not accepting any AI generated contents.

@Tharow
Copy link
Contributor

Tharow commented Mar 8, 2026

Is this your own work? The description reads as if it was created using gen AI. We have strict policy of not accepting any AI generated contents.

Oh didn't even think to check,
Certainly seems highly suspicious.
I'll rewrite the fix myself for this if you want to nuke it, just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileManager(fmActivity) crashes when I enter an invalid VFS: path in the "Go To" dialog

3 participants