RFR: 8190546: File.toPath() reject directory names with trailing space

Maxim Kartashev mkartashev at openjdk.java.net
Thu May 19 13:19:15 UTC 2022


[JDK-8190546](https://bugs.openjdk.java.net/browse/JDK-8190546) is currently closed as will-not-fix with a reference to Win32 documentation [1] that kind of discourages the use of space at the very end of a file name. That documentation says the following:

> Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not


Indeed, it's hard or even impossible to create such a file using the "normal" windows GUI, but you can use that GUI to _delete_ such a file. In Java, you can't do either. 

I'm proposing to lift this restriction primarily based on our user's requests and one or two use cases that seem legitimate.

Working in a cygwin terminal, you can fairly easily create a file name ending with a space. And when you turn to your Java-based IDE to delete it, you get an error from the very basic level of NIO that you can't overrule, which seems to be quite unfortunate. Another source of files legitimately ending with a space would be any Unix filesystem accessed from a Windows Java application (be that a local `\\wsl$` or a NFS mounted from a remote machine). 

If you are interested in moving forward with the issue, please review the PR. Thank you!

References
[1] https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions

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

Commit messages:
 - 8190546: File.toPath() reject directory names with trailing space

Changes: https://git.openjdk.java.net/jdk/pull/8788/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8788&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8190546
  Stats: 78 lines in 3 files changed: 65 ins; 10 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk/pull/8788.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/8788/head:pull/8788

PR: https://git.openjdk.java.net/jdk/pull/8788


More information about the nio-dev mailing list