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

Tilde (~) is not converted to user home dir in Windows

    XMLWordPrintable

Details

    • generic
    • windows

    Description

      FULL PRODUCT VERSION :
      java version "1.7.0_51"
      Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
      Dynamic Code Evolution 64-Bit Server VM (build 24.51-b03-dcevmfull-3, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.10586]

      A DESCRIPTION OF THE PROBLEM :
      Tilde resolves to the working dir instead of intelligently resolving to the user home dir

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      A user enters their home directory in a config file using a tilde (~).
      This doesn't resolve to the user home when on Windows.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect ~ to resolve to user home on Windows.
      ACTUAL -
      It resolves to the working dir

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.nio.file.Path;
      import java.nio.file.Paths;

      public class Test {
        public static void main(String[] args) {
          Path doesntWork = Paths.get("~/.m2");
          System.out.println(doesntWork.toAbsolutePath());
          Path works = Paths.get(System.getProperty("user.home") + "/.m2");
          System.out.println(works.toAbsolutePath());
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      http://stackoverflow.com/questions/7163364/how-to-handle-in-file-paths

      String path = "~/Documents";
      path.replaceFirst("^~", System.getProperty("user.home"));

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: