RFR: 8283335 : Add exists and readAttributesIfExists methods to FileSystemProvider
Brian Burkhalter
bpb at openjdk.org
Fri Jun 24 19:14:41 UTC 2022
On Thu, 23 Jun 2022 07:18:07 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 80:
>>
>>> 78: static UnixFileAttributes getIfExists(UnixPath path) throws UnixException {
>>> 79: UnixFileAttributes attrs = new UnixFileAttributes();
>>> 80: int errno = UnixNativeDispatcher.stat2(path, attrs);
>>
>> I think that this is the only use of `stat2()`. It could be deleted if this method were replaced with this:
>>
>>
>> static UnixFileAttributes getIfExists(UnixPath path) throws UnixException {
>> UnixFileAttributes attrs = new UnixFileAttributes();
>> try {
>> UnixNativeDispatcher.stat(path, attrs);
>> return attrs;
>> } catch (UnixException e) {
>> if (e.errno() == UnixConstants.ENOENT) {
>> return null;
>> }
>> throw e;
>> }
>> }
>
>> I think that this is the only use of `stat2()`. It could be deleted if this method were replaced with this:
>
> The purpose of these additions to the SPI is to improve the performance of user facing methods that don't throw an exception when the file doesn't exist. It needs a stat/equivalent that doesn't throw so this is the reason for stat2. The equivalent on Windows will need to added too.
Understood.
-------------
PR: https://git.openjdk.org/jdk/pull/9249
More information about the nio-dev
mailing list