JDK-8356678 : (fs) Files.readAttributes should map ENOTDIR to NoSuchFileException where possible (unix)
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-05-10
  • Updated: 2025-05-29
  • Resolved: 2025-05-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25 b24Fixed
Related Reports
Blocks :  
Relates :  
Description
Consider the file path "Test.java/foo"where Test.java is a regular file.

On Linux/macOS, the following will throw FileSystemException: Test.java/bar: Not a directory
   Files.readAttributes(file, BasicFileAttributes.class);
   Files.readAttributes(file, PosixFileAttributes.class);

and both of the following will return false as they can't determine if the file exists:
   Files.exists(file);
   Files.notExists(file);

We need to examine the mapping of ENOTDIR in at least UnixFileAttributeViews.Basic.readAttributes, UnixFileAttributeViews.Posixr.eadAttributes, , and UnixFileSystemProvider.checkAccess so that ENOTDIR is treated as ENOENT.  That would change the above so that readAttributes would throw NoSuchFileException for this "unusual" case, and would mean that Files.notExists can return true.

There may be wider scope to map ENOTDIR to NoSuchFileException but would require a detailed pass to see what methods might be impacted.
Comments
Changeset: 3df8ca1e Branch: master Author: Brian Burkhalter <bpb@openjdk.org> Date: 2025-05-15 14:47:02 +0000 URL: https://git.openjdk.org/jdk/commit/3df8ca1ebaf3539363efd569ba9487f5d985117d
15-05-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/25191 Date: 2025-05-12 19:36:22 +0000
12-05-2025