Bug in Files.isSameFile(Path,Path)
WarnerJan Veldhuis
veldhuis at freedom.nl
Fri Oct 23 18:19:31 UTC 2020
Hello nio-dev list,
I ran into a strange bug today, and Stuart Marks told me (cos I asked
him on Twitter) to run this by you. Trying to be a complete as I can here.
My Windows machine has an S: drive that points to a WebDAV location
(https://****.stackstorage.com/remote.php/webdav (identifier removed))
and has been mapped via "Map Network Drive". I can use the drive in
Windows with no problems.
Now, in my code I have two Path objects both pointing to different files
on said S: drive. When I run path1.equals(path2) it returns false as
expected. When I run Files.isSameFile(path1, path2), it returns true,
which is unexpected.
This is the code I use: (imports omitted for brevity)
class FilesTestCase {
public static void main(String[] args) {
try {
System.out.println(System.getProperty("java.version"));
Path file1 = Paths.get("s:/subfolder/file 1.csv");
Path file2 = Paths.get("s:/subfolder/file 2.csv");
System.out.println("equals: " + file1.equals(file2));
System.out.println("is same file: " +
Files.isSameFile(file1, file2));
}
catch (IOException e) {
e.printStackTrace();
}
}
}
The output is :
16-ea
equals: false
is same file: true
I expect the output of "is same file" also to be false.
- The test case is run on a Windows 10 Pro machine, fully patched. The
JDK used was 8 to 16, and they all show the same symptoms.
- So far I could only reproduce this behaviour on a WebDAV drive. This
problem does not occur on "normal" networked drives. I have tried this
on my mapped NAS drives, which is mapped via UNC as \\nas\share, and
then Files::isSameFile returns false as expected.
I hope I could make clear what I found. If there is anything you need
from me, please ask.
Kind regards,
WarnerJan Veldhuis
More information about the nio-dev
mailing list