Reputation: 19243
I've upgraded my PC from Windows 10 to Windows 11 and when I run the following Java code with Java 17, it still returns Windows 10
:
System.getSystemProperty("os.name")
Why is the OS version not updated properly? Is there any location on my PC where this is information pulled from?
If I run the systeminfo
command and check the 2nd line which says "OS Name: "
it correctly reports Microsoft Windows 11 Pro
.
Even the Apache commons-lang3
library relies on the os.name
property which yields the wrong OS version.
Note that this issue occurs only with older versions of Java but the latest Java 19 surprisingly works fine and returns Windows 11 with the os.name
property. What would be the most reliable way to fix this for older Java versions? Parsing systeminfo
? Why do older Java versions not recognize Windows 11 when they could just parse some environment variable or registry entry?
Upvotes: 3
Views: 996
Reputation: 552
Why? Only the implementor that set 'os.name' can tell you for sure, but the likely answer is that they're simply taking the value returned by the OS.
For Windows, the appropriate values are listed here. Note that several systems, with different marketing names, all report themselves as "10.0".
Operating system Version number
Windows 11 10.0*
Windows 10 10.0*
Windows Server 2022 10.0*
Windows Server 2019 10.0*
Windows Server 2016 10.0*
The underlying issue here is that software version numbers, as used by software, do not necessarily equate cleanly to what the marketing division wants to write on the box the system comes in.
Microsoft recommends against basing application code on a specific version number.
Upvotes: 2