RFR: 8354450: Using a File with a path containing a trailing space should fail when alternative data streams are disabled (win) [v2]

Brian Burkhalter bpb at openjdk.org
Fri Apr 18 18:24:56 UTC 2025


On Fri, 18 Apr 2025 08:11:28 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> From experimentation with C++ code is VS, it appears that `CreateDirectoryW` will create a directory with either a leading or trailing space in its name, whereas `createFileW` will create a file with a leading space in its name, but a trailing space is trimmed.
>
>> From experimentation with C++ code is VS, it appears that `CreateDirectoryW` will create a directory with either a leading or trailing space in its name, whereas `createFileW` will create a file with a leading space in its name, but a trailing space is trimmed.
> 
> Right, the Windows APIs are very inconsistent on this, and why the Windows implementation of Path will always reject input where an element has a trailing space.

It turns out that a case such as `foo \bar\gus` already fails in `File.mkdirs` due to directory creation itself, so an explicit check for a trailing space in directory elements does not appear to be necessary, although having the failure occur in `isInvalid` would be more fail-fast.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24635#discussion_r2050965482


More information about the core-libs-dev mailing list