views:

540

answers:

2

I have stumbled across something truly puzzling regarding System.getProperty("os.name"). According to a Java bug on the matter and the Java 5 release notes (search for "os.name"), there was a bug in Java with early "longhorn" versions of Vista that should have been fixed in v5 release 10.

However on my Vista SP1 box - using both v5 release 15 and v6 release 6 - System.getProperty("os.name") returns "Windows XP". Further System.getProperty("os.version") returns "5.1". I cannot find anything relating to this issue via Google though. This makes me wonder whether it is something odd with my Vista setup. I have tried calling the GetVersionEx() API function from a test C program and it returns major version 6, minor 0 (as I'd expect for a Vista install).

Has anyone else encountered this problem, know of a fix or have any suggestions of how I might work around it without using JNI?

A: 

The actual windows version number of Windows 2000 was 5.0. Windows XP was 5.1. Vista is supposedly 6.0, so your test program is functioning correctly. It sounds to me like Java is definitely getting this wrong.

You might have to rely on a JNI to get the right answer. I sort of assume that you've already asked yourself why you might need to vary the behavior of your program based on whether you're using XP or Vista.

nsayer
The answer to why I need to vary the behaviour is simple: symlinks. They exist in Vista and not in XP ;)
David Arno
Check Martin's answer, it's really good!
Hosam Aly
+8  A: 

It might be that Java runs in XP compatibility mode. In that case, Vista will fake the windows version number, making Java believe that it runs on XP. Check the compatibility tab of the executable.

Martin v. Löwis
You are a genius sir! :) I was running Eclipse in compatibility mode as the automatic scrolling feature in Vista makes Eclipse near-unusable. As a result, it was running any Java code I launched from Eclipse in compatibility mode too. It reports Vista just fine with compatibility mode turned off :D
David Arno