RFR: 8287843: File::getCanonicalFile doesn't work for \?\C:\ style paths DOS device paths
Brian Burkhalter
bpb at openjdk.org
Thu Sep 7 16:01:41 UTC 2023
On Thu, 7 Sep 2023 08:33:39 GMT, Alan Bateman <alanb at openjdk.org> wrote:
> Would it be possible to summarise how this behaves when File just represents a prefix?
Baseline:
jshell> File f = new File("\\\?\")
f ==> \?
jshell> f.getCanonicalPath()
| Exception java.io.IOException: Bad pathname
| at WinNTFileSystem.canonicalize0 (Native Method)
| at WinNTFileSystem.canonicalize (WinNTFileSystem.java:463)
| at File.getCanonicalPath (File.java:626)
| at (#2:1)
jshell> f = new File("\\\?\\UNC\")
f ==> \?\UNC
jshell> f.getCanonicalPath()
| Exception java.io.IOException: Bad pathname
| at WinNTFileSystem.canonicalize0 (Native Method)
| at WinNTFileSystem.canonicalize (WinNTFileSystem.java:463)
| at File.getCanonicalPath (File.java:626)
| at (#4:1)
Proposed patch:
jshell> File f = new File("\\\?\")
f ==> \?
jshell> f.getCanonicalPath()
| Exception java.io.IOException: Bad pathname
| at WinNTFileSystem.canonicalize0 (Native Method)
| at WinNTFileSystem.canonicalize (WinNTFileSystem.java:472)
| at File.getCanonicalPath (File.java:626)
| at (#2:1)
jshell> f = new File("\\\?\\UNC\")
f ==> \?\UNC
jshell> f.getCanonicalPath()
$4 ==> "C:\\Users\\bpb\\dev\\jdk\\jdk\\UNC"
Presumably the constructor removes the trailing `\`, hence I suppose the special case of `\?\UNC` should be checked in the code right after the proposed change.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/15603#issuecomment-1710409880
More information about the core-libs-dev
mailing list