Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8191963

Path.equals() and File.equals() return true for two different files on Windows

XMLWordPrintable

    • In Review
    • x86_64
    • windows

      FULL PRODUCT VERSION :
      java version "9.0.1"
      Java(TM) SE Runtime Environment (build 9.0.1+11)
      Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)

      java version "1.8.0_152"
      Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
      Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.16299.64]

      A DESCRIPTION OF THE PROBLEM :
      Path.equals() and File.equals() return true for file names that can exist as different files on Windows.
      Even though equals() returns true, it can be created as a different file using Files.createFile() or File.createNewFile().

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      java.exe Main.java
      javac.exe Main

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      false
      false
      false
      false
      ACTUAL -
      true
      false
      true
      true

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.nio.file.Paths;

      public class Main {

          public static void main(String[] args) {
              // U+0131 = ı 'LATIN SMALL LETTER DOTLESS I'
              // U+0130 = İ 'LATIN CAPITAL LETTER I WITH DOT ABOVE'
              System.out.println(Paths.get("\u0131").equals(Paths.get("I")));
              System.out.println(Paths.get("\u0130").equals(Paths.get("I")));
              System.out.println(new File("\u0131").equals(new File("I")));
              System.out.println(new File("\u0130").equals(new File("I")));
          }
      }
      ---------- END SOURCE ----------

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: