JDK-8179615 : Wrong os.name property in Windows 10 when run in the compatibility mode
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 8u60,9
  • Priority: P3
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: windows_10
  • CPU: x86
  • Submitted: 2017-04-29
  • Updated: 2017-06-06
  • Resolved: 2017-05-24
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 10

EXTRA RELEVANT SYSTEM CONFIGURATION :
Running on compatibility mode (for example, Windows 7)

A DESCRIPTION OF THE PROBLEM :
Try this below code in a number of Java version / vendor combinations in Windows 10 OS, after each of the 'java' executbale made compatible with Windows 7.


C:\foo>cat OSN.java
public class OSN {
  public static void main(String args[]) {
    System.out.println(System.getProperty("os.name"));
  }
}

C:\foo>java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build pwa6480sr3-20160428_01(SR3))
IBM J9 VM (build 2.8, JRE 1.8.0 Windows 7 amd64-64 Compressed References 20160427_301573 (JIT enabled, AOT enabled)
J9VM - R28_Java8_SR3_20160427_1620_B301573
JIT  - tr.r14.java.green_20160329_114288
GC   - R28_Java8_SR3_20160427_1620_B301573_CMPRSS
J9CL - 20160427_301573)
JCL - 20160421_01 based on Oracle jdk8u91-b14

C:\foo>java OSN
Windows 7

C:\foo>..\java7\bin\java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

C:\foo>..\java7\bin\java OSN
Windows 7

C:\foo>..\java8\jdk1.8.0\bin\java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

C:\foo>..\java8\jdk1.8.0\bin\java OSN
Windows 7

C:\foo>..\java8_u51\bin\java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

C:\foo>..\java8_u51\bin\java OSN
Windows 7

C:\foo>"C:\Program Files\Java\jre1.8.0_131\bin\java.exe" -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

C:\foo>"C:\Program Files\Java\jre1.8.0_131\bin\java.exe" OSN
Windows 10

Oracle Java 8 version does not turn os.name property into Windows 7 when run in the compatibility mode

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run this code on Windows 10, running in compatibility mode
public class OSN {
  public static void main(String args[]) {
    System.out.println(System.getProperty("os.name"));
  }
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Windows 7
ACTUAL -
Windows 10

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class OSN {
  public static void main(String args[]) {
    System.out.println(System.getProperty("os.name"));
  }
}
---------- END SOURCE ----------


Comments
The version number reported by os.name should be stable and not a function settable by the application. The current implementation that uses the version of the kernel.dll provides that stable version number. An application with a native implementation sensitive to the compatibility mode also has the ability to detect the OS version using the getVersionEx or similar.
24-05-2017

The extraction of the os.name from the Windows version parameters was changed after 8u_51 to correctly report the accurate window version number by reading the version number from kernel.dll. Some more investigation is needed to determine how the compatibility mode is reported by the various version number APIs. os.name is accurately reporting the running version of Windows. There may also be a question of the meaning of os.version and whether it should indicate the compatibility mode or the true Windows version.
09-05-2017

This is a regression introduced in JDK 8u60. Until JDK 8u51, when run in compatibility mode (Windows 7) , the os.name displays Windows 7, JDK 8u60 onwards until JDK 8u131 displays Windows 10. JDK 8u20 -Pass JDK 8u51 - Pass JDK 8u60 - Fail JDk 8u131 - Fail JDk 9-ea +167 - Fail
04-05-2017