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?