On Tue, 22 Apr 2025 17:46:04 GMT, Brian Burkhalter <b...@openjdk.org> wrote:
>> src/java.base/windows/classes/java/io/WinNTFileSystem.java line 376: >> >>> 374: return true; >>> 375: theFile = theFile.getParentFile(); >>> 376: } while (theFile != null); >> >> The input has already been normalized so I think you can reduce it down to >> searching getPath for a trailing space or a space followed by a backslash. > > Using `Path.of` with various inputs yields the following: > > "root\dir\subdir\file.txt" is valid > "root \dir\subdir\file.txt" is invalid > "root\ dir\subdir\file.txt" is valid > "root\dir \subdir\file.txt" is invalid > "root\dir\ subdir\file.txt" is valid > "root\dir\subdir \file.txt" is invalid > "root\dir\subdir\ file.txt" is valid > "root\dir\subdir\file.txt " is invalid > > Apparently that method at least thinks that a backslash followed by a space > is acceptable ("invalid" == `InvalidPathException` caught). The equivalent results for the preceding but using `File`, `mkdirs`, and `createNewFile` are: "root\dir\subdir\file.txt" is valid "root \dir\subdir\file.txt" is invalid The system cannot find the path specified "root\ dir\subdir\file.txt" is valid "root\dir \subdir\file.txt" is invalid The system cannot find the path specified "root\dir\ subdir\file.txt" is valid "root\dir\subdir \file.txt" is invalid The system cannot find the path specified "root\dir\subdir\ file.txt" is valid "root\dir\subdir\file.txt " is valid So the current `java.io` restriction matches the `java.nio.file` restriction except for the trailing space in the filename element. Note however that `Path` catches the bad pathname whereas for `java.io` one needs actually to attempt to create the file or directory before invalidity is detected. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/24635#discussion_r2054603003