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

Clearing system property user.dir causes File methods to throw NPE

    XMLWordPrintable

Details

    Description

      If a File is relative then operations that require current directory, e.g. getAbsoluteFile(), getCanonicalPath(), fail with NPE if user.dir property has been previously cleared (via clearProperty(String) or setProperties(Properties)).
      ====================
      Example:
      jshell> new File("foo/bar").getAbsoluteFile()
      $1 ==> d:\\foo\bar

      jshell> System.clearProperty("user.dir");
      $2 ==> "d:\\"

      jshell> new File("foo/bar").getAbsoluteFile()
      | java.lang.NullPointerException thrown:
      | at WinNTFileSystem.normalize (WinNTFileSystem.java:83)
      | at WinNTFileSystem.getUserPath (WinNTFileSystem.java:349)
      | at WinNTFileSystem.resolve (WinNTFileSystem.java:312)
      | at File.getAbsolutePath (File.java:556)
      | at File.getAbsoluteFile (File.java:572)
      | at (#3:1)
      ====================

      Note that with empty user.dir calls don't fail.
      Example:
      ====================
      jshell> System.setProperty("user.dir", "");
      $4 ==> null

      jshell> new File("foo/bar").getAbsoluteFile()
      $5 ==> \foo\bar
      ====================

      Attachments

        Issue Links

          Activity

            People

              rriggs Roger Riggs
              slukyanov Stanislav Lukyanov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: