RFR: 8355342: File.getCanonicalPath on Java 24 resolves paths on network drives to UNC format [v6]
Brian Burkhalter
bpb at openjdk.org
Tue Oct 21 20:11:27 UTC 2025
On Tue, 21 Oct 2025 14:54:47 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:
> Can you do the same for without the patch? Also I think keep links out of the examples for now [...].
The following tables are for `Z:` mapped to `C:\Temp`.
### JDK 23
| pathname | getCanonicalPath | toRealPath |
| :---: | :---: | :---: |
| z:\file.txt | Z:\file.txt | Z:\file.txt |
| z:\notexist.txt | Z:\notexist.txt | java.nio.file.NoSuchFileException z:\notexist.txt |
| \\127.0.0.1\z$\temp\file.txt | \\127.0.0.1\z$\temp\file.txt | java.nio.file.FileSystemException \\127.0.0.1\z$\temp\file.txt: The network name cannot be found |
| \\LOCALHOST\z$\temp\file.txt | \\LOCALHOST\z$\temp\file.txt | java.nio.file.FileSystemException \\LOCALHOST\z$\temp\file.txt: The network name cannot be found |
| \.\z:\file.txt | \.\z:\file.txt | java.nio.file.InvalidPathException Illegal character [:] in path at index 5: \.\z:\file.txt |
| \?\z:\file.txt | Z:\file.txt | Z:\file.txt |
| \.\UNC\LOCALHOST\z$\temp\file.txt | java.io.IOException The filename, directory name, or volume label syntax is incorrect | java.nio.file.FileSystemException \.\UNC\LOCALHOST\z$\temp\file.txt: The filename, directory name, or volume label syntax is incorrect |
| .\file.txt | C:\Temp\file.txt | C:\Temp\file.txt |
### JDK 24
| pathname | getCanonicalPath | toRealPath |
| :---: | :---: | :---: |
| z:\file.txt | \\localhost\c$\Temp\file.txt | Z:\file.txt |
| z:\notexist.txt | Z:\notexist.txt | java.nio.file.NoSuchFileException z:\notexist.txt |
| \\127.0.0.1\z$\temp\file.txt | \\127.0.0.1\z$\temp\file.txt | java.nio.file.FileSystemException \\127.0.0.1\z$\temp\file.txt: The network name cannot be found |
| \\LOCALHOST\z$\temp\file.txt | \\LOCALHOST\z$\temp\file.txt | java.nio.file.FileSystemException \\LOCALHOST\z$\temp\file.txt: The network name cannot be found |
| \.\z:\file.txt | \\localhost\c$\Temp\file.txt | java.nio.file.InvalidPathException Illegal character [:] in path at index 5: \.\z:\file.txt |
| \?\z:\file.txt | \\localhost\c$\Temp\file.txt | Z:\file.txt |
| \.\UNC\LOCALHOST\z$\temp\file.txt | java.io.IOException The filename, directory name, or volume label syntax is incorrect | java.nio.file.FileSystemException \.\UNC\LOCALHOST\z$\temp\file.txt: The filename, directory name, or volume label syntax is incorrect |
| .\file.txt | C:\Temp\file.txt | C:\Temp\file.txt |
### Current Patch
| pathname | getCanonicalPath | toRealPath |
| :---: | :---: | :---: |
| z:\file.txt | Z:\file.txt | Z:\file.txt |
| z:\notexist.txt | Z:\notexist.txt | java.nio.file.NoSuchFileException z:\notexist.txt |
| \\127.0.0.1\z$\temp\file.txt | \\127.0.0.1\z$\temp\file.txt | java.nio.file.FileSystemException \\127.0.0.1\z$\temp\file.txt: The network name cannot be found |
| \\LOCALHOST\z$\temp\file.txt | \\LOCALHOST\z$\temp\file.txt | java.nio.file.FileSystemException \\LOCALHOST\z$\temp\file.txt: The network name cannot be found |
| \.\z:\file.txt | \\localhost\c$\Temp\file.txt | java.nio.file.InvalidPathException Illegal character [:] in path at index 5: \.\z:\file.txt |
| \?\z:\file.txt | Z:\file.txt | Z:\file.txt |
| \.\UNC\LOCALHOST\z$\temp\file.txt | java.io.IOException The filename, directory name, or volume label syntax is incorrect | java.nio.file.FileSystemException \.\UNC\LOCALHOST\z$\temp\file.txt: The filename, directory name, or volume label syntax is incorrect |
| .\file.txt | C:\Temp\file.txt | C:\Temp\file.txt |
### Differences
The differences among the above tables for the `getCanonicalPath` output are:
| pathname | JDK 23 | JDK 24 | Patch |
| :---: | :---: | :---:| :--- |
| z:\file.txt | Z:\file.txt | \localhost\c$\Temp\file.txt | Z:\file.txt |
| \.\z:\file.txt | \.\z:\file.txt | \localhost\c$\Temp\file.txt | \localhost\c$\Temp\file.txt |
| \?\z:\file.txt | Z:\file.txt | \localhost\c$\Temp\file.txt | Z:\file.txt |
The patch brings back two of the cases to JDK 23 behavior, but misses the case of `.\z:\file.txt`. This could be due to the prefix `"\\\?\"` being stripped in `WinNTFileSystem`, whereas the prefix `"\\\.\"` is not.
Note also that for `z:\notexist.txt`, `getCanonicalPath` returns `Z:\notexist.txt`, whereas `toRealPath` always throws `NoSuchFileException`.
The NIO results are, of course, the same for all JDKs versions.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/27324#issuecomment-3429386112
More information about the core-libs-dev
mailing list