Skip to content

Throw IOException from FileUtils.getContentsAsString when the file cannot be read - #652

Open
Sarthak-Shreshtha01 wants to merge 1 commit into
javapathfinder:masterfrom
Sarthak-Shreshtha01:fix/filecontents-ioexception
Open

Sarthak-Shreshtha01 wants to merge 1 commit into
javapathfinder:masterfrom
Sarthak-Shreshtha01:fix/filecontents-ioexception

Conversation

@Sarthak-Shreshtha01

Copy link
Copy Markdown

getContentsAsString(File) passed the null from getContents(File) straight to new String(), so reading a directory or an unreadable file threw a NullPointerException. It now throws an IOException naming the file. getContents(File) is unchanged, since CachedROHttpConnection relies on its null return.

Added FileUtilsTest: one test reads a file normally, one reads a directory and expects IOException (it failed with the NPE before this change).

Fixes #649

…nnot be read

getContents(File) returns null for a directory, a missing file or a
failed read, and getContentsAsString passed that null to new String(),
so callers got a NullPointerException instead of the IOException the
method declares.

Fixes javapathfinder#649

Signed-off-by: Sarthak <sarthakshreshtha345@gmail.com>
Copilot AI balanced review requested due to automatic review settings October 14, 2026 19:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
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.

FileUtils.getContentsAsString() throws NullPointerException instead of IOException

2 participants