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

Reviewed-by: alanb
This commit is contained in:
Brian Burkhalter 2022-06-09 16:30:53 +00:00
parent edff51e5fd
commit d482d7f5b9
2 changed files with 44 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -374,8 +374,19 @@ class WindowsFileSystemProvider
}
}
// check file exists only
if (!(r || w || x)) {
file.checkRead();
try {
WindowsFileAttributes.get(file, true);
return;
} catch (WindowsException exc) {
exc.rethrowAsIOException(file);
}
}
// special-case read access to avoid needing to determine effective
// access to file; default if modes not specified
// access to file
if (!w && !x) {
checkReadAccess(file);
return;