Summary
Remove extended-length and UNC prefixes when normalizing java.io.File
pathnames.
Problem
java.io.File
instances constructed from path names beginning with the extended-length (long) path prefix "\?\" or the related universal naming convention (UNC) path prefix "\?\UNC\" [1] have inconsistent behavior with respect to File
s created by equivalent path names without the prefix. For example, given the pathname \\?\C:\foo\bar
containing a long path prefix, the method File.getCanonicalPath
throws java.io.IOException: Bad pathname
with the prefix in place, but returns the correct value, C:\foo\bar
, if the prefix is first removed.
[1] https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry
Solution
Strip the long path prefix \\?\
or UNC prefix \\?\UNC\
when the supplied path name is normalized. Initially it had been thought to strip the prefix in various individual methods, for example, getCanonicalPath
, and isAbsolute
, as appropriate, but it turns out that the path is already normalized by the time those methods are invoked.
Specification
There is no change to the specification.
- csr of
-
JDK-8287843 File::getCanonicalFile doesn't work for \\?\C:\ style paths DOS device paths
- Closed