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

(fs) Paths.get("x").relativize("") return ..\ on Windows

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • core-libs
    • b124
    • windows
    • Verified

      The result should be "..". In fact, the current return value is quite strange that its getName(0) is also ..\. Seems like \ is not treated as a path separator.

      The problem is inside relativize() of WindowsPath.java:

       416 // append remaining names in child
       417 for (int j=i; j<cn; j++) {
       418 result.append(other.getName(j).toString());
       419 result.append("\\");
       420 }

      Here, when other.getName(j).toString() is empty, a backslash should not be added.

      Another similar issue. Paths.get("D:").toAbsolutePath() becomes D:\xyz\ instead of D:\xyz. The WindowsPath::getAbsolutePath() method leaves a trailing slash when remaining is empty below.

       252 result = defaultDirectory + "\\" + remaining;

            alanb Alan Bateman
            weijun Weijun Wang
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: