JDK-8202127 : System.setProperty("user.dir","xxx") has no effect on File.getAbsolutePath
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 11
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2018-04-20
  • Updated: 2018-07-13
  • Resolved: 2018-04-23
Description
ADDITIONAL SYSTEM INFORMATION :
openjdk 11-ea 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11-ea+10)
OpenJDK 64-Bit Server VM 18.9 (build 11-ea+10, mixed mode)

Mac OS X 10.12.1

A DESCRIPTION OF THE PROBLEM :
        System.out.println(new java.io.File("a").getAbsolutePath());
        System.setProperty("user.dir", "/User/zhb");
        System.out.println(new java.io.File("a").getAbsolutePath());

On Java 10 or lower, the output is:

/the/current/working/dir/a
/User/zhb/a

On Java 11 ea, the output is:

/the/current/working/dir/a
/the/current/working/dir/a

REGRESSION : Last worked in version 11

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
class MyTest {
    public static void main(String []args){
        System.out.println(new java.io.File("a").getAbsolutePath());
        System.setProperty("user.dir", "/User/zhb");
        System.out.println(new java.io.File("a").getAbsolutePath());
    }
}


Compile and run on Java 10 and Java 11 repectively.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Keep the previous behaviour
ACTUAL -
Different behavior as Java 1-

CUSTOMER SUBMITTED WORKAROUND :
No found yet.

FREQUENCY : always



Comments
See also the API note in the System getProperty/setProperty/getProperties javadoc: "Changing a standard system property may have unpredictable results unless otherwise specified. Property values may be cached during initialization or on first use. Setting a standard property after initialization using getProperties(), setProperties(Properties), setProperty(String, String), or clearProperty(String) may not have the desired effect."
13-07-2018

This is not a bug. The "user.dir" property should never be changed in a running VM.
20-04-2018