RFR: 8374441: FileSystemProvider.readAttributesIfExists should return null for ENOTDIR (unix)

Alan Bateman alanb at openjdk.org
Mon Jan 5 12:58:48 UTC 2026


On Wed, 31 Dec 2025 21:14:29 GMT, Fabian Meumertzheim <fmeum at openjdk.org> wrote:

> `FileSystemProvider.readAttributesIfExists` now returns `null` for a path with a true prefix that is not a directory rather than throwing `NotDirectoryException`.

>  Title mismatch between PR and JBS.

Can you update the PR title to match the JBS issue?

src/java.base/unix/classes/sun/nio/fs/UnixFileAttributes.java line 102:

> 100:             return attrs;
> 101:         else if (errno == UnixConstants.ENOENT ||
> 102:                  errno == UnixConstants.ENOTDIR)

I think this is okay. Can you update the end copyright from 2025 to 2026.

test/jdk/java/nio/file/Files/NotADirectory.java line 54:

> 52: 
> 53: import static org.junit.jupiter.api.Assertions.assertFalse;
> 54: import static org.junit.jupiter.api.Assertions.assertNull;

The tests in Files/* are meant to test the FIles API. I suppose it's okay to have it also test a related/underlying FileSystemProvider method but it will mean we need to update the test summary. Also need to add the JBS issue number to the `@bug` line.

test/jdk/java/nio/file/Files/NotADirectory.java line 151:

> 149:         assertNull(
> 150:             BOGUS.getFileSystem().provider().readAttributesIfExists(
> 151:                 BOGUS, BasicFileAttributes.class));

You can define a constant `static final FileSystemProvider PROVIDER = FileSystems.getDefault().provider()` and it will clean up these two tests.

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

PR Comment: https://git.openjdk.org/jdk/pull/29013#issuecomment-3710305339
PR Review Comment: https://git.openjdk.org/jdk/pull/29013#discussion_r2661384778
PR Review Comment: https://git.openjdk.org/jdk/pull/29013#discussion_r2661387754
PR Review Comment: https://git.openjdk.org/jdk/pull/29013#discussion_r2661395319


More information about the nio-dev mailing list