google / google/error-prone

Files.isDirectory and friends are unsafe

Open
#1,388 0 comments 3 reactions 0 assignees View on GitHub
Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

### Description of the problem / feature request:

Files.isDirectory, Files.isRegularFile and Files.isSymbolicLink ignore all IOExceptions (not just FileNotFound). This is almost never what you want; you want genuine IOExceptions like "the hard drive is on fire", or "the network is down, so NFS is not working" to get propagated.

These functions should not be used. ErrorProne should suggest Files.readAttributes instead. Automatic rewriting is hard because readAttributes throws IOException while the functions to be replaced do not.

### Feature requests: what underlying problem are you trying to solve with this feature?

To replace unsafe functions with safe ones.

### What version of Error Prone are you using?

3433532241b41f8e682a519122b5525320558c35 (HEAD as of Oct 10, 2019)

### Have you found anything relevant by searching the web?

I searched the bug tracker and mailing list for Files.isDirectory and found nothing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.