RFR: 8283335 : Add exists and readAttributesIfExists methods to FileSystemProvider

Lance Andersen lancea at openjdk.org
Fri Jun 24 10:44:02 UTC 2022


On Thu, 23 Jun 2022 08:05:42 GMT, Chris Hegarty <chegar at openjdk.org> wrote:

>> Hi,
>> 
>> Please review the following patch which will:
>> 
>> - Enhance the java.nio.file.spi.FileSystemProvider abstract class to include the methods
>> 
>>   - public boolean exists(Path path, LinkOption... options)
>>   - public <A extends BasicFileAttributes> A readAttributesIfExists(Path path, Class<A> type, LinkOption... options)
>> 
>> 
>> This change allows for providers to provide optimizations when the file's attributes are not needed.
>> 
>> Mach5 tiers 1 - 3  run clean with this change
>> 
>> The CSR may be viewed at [JDK-8283336](https://bugs.openjdk.org/browse/JDK-8283336)
>> 
>> 
>> Best,
>> Lance
>
> src/java.base/share/classes/java/nio/file/spi/FileSystemProvider.java line 1202:
> 
>> 1200:      */
>> 1201:     public boolean exists(Path path, LinkOption... options) {
>> 1202:         try {
> 
> Overall, I think that this is a great change (avoiding the need for various parts of the system to communicate through exceptions).
> 
> Trivially, and easily, I often find it useful to add mock-like tests for these specified implementations (implSpec), i.e. just subclass FSP mocking out the abstract methods to ensure that the default implementations invoke the appropriate ones.

Thank you for the suggestion Chris

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

PR: https://git.openjdk.org/jdk/pull/9249


More information about the core-libs-dev mailing list