Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8356678

(fs) Files.readAttributes should map ENOTDIR to NoSuchFileException where possible (unix)

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • core-libs
    • None
    • In Review

      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.

            bpb Brian Burkhalter
            alanb Alan Bateman
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: