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

java.io.File(String,String) creates wrong path if 2nd param starts with \

XMLWordPrintable

    • x86
    • windows_nt


      File f = new File("c:\tmp","\foo")

      creates a File with "c:\tmp\foo" as full path.

      according to bug 4179128 the 2nd param should not be absolute, so it should be checked before attempting the creation of the File object.

      File("\\foo").isAbsolute() returns false, according to bug 4242635 this is correct because it can not be any ambiguity in the file name in order to be absolute (i.e.: the drive letters in win).

      the recommendation of bug 4179128 does not work

      String absName = "c:\\tmp";
      String relName = "\\foo";

      File file = new File(relName);
      if (file.isAbsolute()) {
      file = new File(absName,relName);
      }

      creates a file with path "c:\\tmp\\foo" when the path should be "c:\\foo"




            kkladkosunw Konstantin Kladko (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: