-
Bug
-
Resolution: Duplicate
-
P4
-
None
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
====================
====================
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
====================
- duplicates
-
JDK-8194154 System property user.dir should not be changed
-
- Closed
-
- relates to
-
JDK-4165411 java.lang.System: Forbid the modification of read-only system properties
-
- Open
-
-
JDK-8066709 Make some JDK system properties read only
-
- Resolved
-