Bug in Files.isSameFile(Path,Path)

Nikola Grcevski Nikola.Grcevski at microsoft.com
Fri Oct 23 19:46:20 UTC 2020


Thanks for reporting this WarnerJan, we'll take a look.

Nikola Grcevski,
Microsoft

From: nio-dev <nio-dev-retn at openjdk.java.net> On Behalf Of WarnerJan Veldhuis
Sent: October 23, 2020 3:39 PM
To: nio-dev at openjdk.java.net
Subject: Re: Bug in Files.isSameFile(Path,Path)

Thanks for the suggestion.

I tried various ways of grabbing paths, all yield the (wrong) result:

Paths.get("s:\\subfolder\\file 1.csv");
Paths.get("s:", "subfolder" , "file 1.csv");
Paths.get("s:/subfolder/file 1.csv").normalize();
new File("s:/subfolder/file 1.csv").toPath();
new File("s:/subfolder/file 1.csv").getAbsoluteFile().toPath()

To add to the orignal bug report, I was notified by one of my customers of this, and he used a drive mapped to a Sharepoint URL. I assume that's WebDAV under the hood.

Kind regards,

WarnerJan


On 23/10/2020 21:31, Bernd Eckenfels wrote:
Maybe the problem is using / as path separator, did you try s:\\...  or normalize()?

Gruss
Bernd


--
http://bernd.eckenfels.net<https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fbernd.eckenfels.net%2F&data=04%7C01%7CNikola.Grcevski%40microsoft.com%7Ce31d76f757de44481c9708d8778b69db%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637390787965506301%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=tR94Sy3EOVWos%2FcWEhzYd%2FbQ%2ByoQb6sm9K%2FVsFgwoHo%3D&reserved=0>
________________________________
Von: nio-dev <nio-dev-retn at openjdk.java.net><mailto:nio-dev-retn at openjdk.java.net> im Auftrag von WarnerJan Veldhuis <veldhuis at freedom.nl><mailto:veldhuis at freedom.nl>
Gesendet: Friday, October 23, 2020 8:19:31 PM
An: nio-dev at openjdk.java.net<mailto:nio-dev at openjdk.java.net> <nio-dev at openjdk.java.net><mailto:nio-dev at openjdk.java.net>
Betreff: Bug in Files.isSameFile(Path,Path)

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<file://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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20201023/18662198/attachment-0001.htm>


More information about the nio-dev mailing list