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

File.getCanonicalPath can return non-canonical path on Windows

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6u45
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version " 1.6.0_45 "
      Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
      Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      It is possible to build a File object with a trailing backslash in its canonical representation (returned by the method getCanonicalPath).

      This trailing backslash makes the representation non-canonical (non-unique) as the same path without the trailing backslash will represent the same file but with a different representation.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      File f = new File( " c:\\Program Files " );
      File f2 = new File(f, " \\ " ); // problem
      File f3 = new File(f, " \\.\\ " ); // resolves correctly
      System.out.println(f.getCanonicalPath());
      System.out.println(f2.getCanonicalPath());
      System.out.println(f3.getCanonicalPath());

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      C:\Program Files
      C:\Program Files
      C:\Program Files
      ACTUAL -
      C:\Program Files
      C:\Program FilesC:\Program Files

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.io.IOException;

      /**
       * TestCanonical
       *
       */
      public class TestCanonical {

          public static void main(String[] args) throws IOException {
              File f = new File( " c:\\Program Files " );
              File f2 = new File(f, " \\ " ); // problem
              File f3 = new File(f, " \\.\\ " ); // resolves correctly
              System.out.println(f.getCanonicalPath());
              System.out.println(f2.getCanonicalPath());
              System.out.println(f3.getCanonicalPath());
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: