RFR: 8286160: (fs) Files.exists returns unexpected results with C:\pagefile.sys because it's not readable

Alan Bateman alanb at openjdk.java.net
Tue Jun 7 09:32:53 UTC 2022


On Mon, 6 Jun 2022 22:28:47 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> If in `WindosFileSystemProvider.checkAccess(Path obj, AccessMode... modes)` the sub-test `checkReadAccess(WindowsPath)` fails and no modes are specified, then try to determine file existence by reading the file's attributes.

src/java.base/windows/classes/sun/nio/fs/WindowsFileSystemProvider.java line 395:

> 393:                 }
> 394:                 throw ioe;
> 395:             }

Testing the existence of a file is performance issue in some usages and would be interesting to see if this would be a bit better.


        // check file exists only
        if (!r && !w && !x) {
            file.checkRead();
            try {
                WindowsFileAttributes.get(file, true);
                return;
            } catch (WindowsException e) {
                exc.rethrowAsIOException(file);
            }
        }

-------------

PR: https://git.openjdk.java.net/jdk/pull/9045


More information about the nio-dev mailing list