Bug in Files.isSameFile(Path,Path)
WarnerJan Veldhuis
veldhuis at freedom.nl
Fri Oct 23 19:39:14 UTC 2020
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
> ------------------------------------------------------------------------
> *Von:* nio-dev <nio-dev-retn at openjdk.java.net> im Auftrag von
> WarnerJan Veldhuis <veldhuis at freedom.nl>
> *Gesendet:* Friday, October 23, 2020 8:19:31 PM
> *An:* nio-dev at openjdk.java.net <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/fd9d7aca/attachment.htm>
More information about the nio-dev
mailing list