RFR: 8356678: (fs) Files.readAttributes should map ENOTDIR to NoSuchFileException where possible (unix) [v2]

Alan Bateman alanb at openjdk.org
Wed May 14 05:42:52 UTC 2025


On Tue, 13 May 2025 23:53:38 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Treat `ENOTDIR` as causing a `NoSuchFileException` instead of a `FileSystemExcception` in some places in order to handle cases such as a regular file named, for example, `foo/bar`.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8356678: Add more checks in copy and move; beef up test

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java line 487:

> 485:             if (x.errno() == ENOTDIR) {
> 486:                 x.setError(ENOENT);
> 487:             }

This is the mkdir to create the target so I don't think we should change this as it would be very confusing to see NoSuchFileException here.

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java line 638:

> 636:                 if (x.errno() == ENOTDIR) {
> 637:                     x.setError(ENOENT);
> 638:                 }

This is also the target so I don't think this should be changed.

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java line 829:

> 827:                         x.errorString());
> 828:                 } else if (x.errno() == ENOTDIR) {
> 829:                     x.setError(ENOENT);

This is rename where the issue might be the source or target path. So I think we have to drop this change too.

src/java.base/unix/classes/sun/nio/fs/UnixFileSystem.java line 904:

> 902:                 if (x.errno() == ENOTDIR) {
> 903:                     x.setError(ENOENT);
> 904:                 }

This is also a rename so need to drop this change too.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25191#discussion_r2088076276
PR Review Comment: https://git.openjdk.org/jdk/pull/25191#discussion_r2088076710
PR Review Comment: https://git.openjdk.org/jdk/pull/25191#discussion_r2088077437
PR Review Comment: https://git.openjdk.org/jdk/pull/25191#discussion_r2088078923


More information about the nio-dev mailing list