8160370: System.getProperty("os.version") returns "Unknown" on Mac
authorbchristi
Thu, 30 Jun 2016 10:13:30 -0700
changeset 39322 66ecf193683a
parent 39321 c60f34e8c057
child 39330 6f808f6d8684
8160370: System.getProperty("os.version") returns "Unknown" on Mac Summary: Read SystemVersion.plist on pre-10.9 Mac OS Reviewed-by: bpb, ddehaven, gziemski, rriggs
jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
--- a/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jun 30 22:24:01 2016 +0530
+++ b/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jun 30 10:13:30 2016 -0700
@@ -182,7 +182,17 @@
         // Copy out the char*
         osVersionCStr = strdup([nsVerStr UTF8String]);
     }
-
+    // Fallback if running on pre-10.9 Mac OS
+    if (osVersionCStr == NULL) {
+        NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile :
+                                 @"/System/Library/CoreServices/SystemVersion.plist"];
+        if (version != NULL) {
+            NSString *nsVerStr = [version objectForKey : @"ProductVersion"];
+            if (nsVerStr != NULL) {
+                osVersionCStr = strdup([nsVerStr UTF8String]);
+            }
+        }
+    }
     if (osVersionCStr == NULL) {
         osVersionCStr = strdup("Unknown");
     }
@@ -190,7 +200,9 @@
 }
 
 
-static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey, CFStringRef inHostKey, CFStringRef inPortKey, CFStringRef *outProxyHost, int *ioProxyPort) {
+static Boolean getProxyInfoForProtocol(CFDictionaryRef inDict, CFStringRef inEnabledKey,
+                                       CFStringRef inHostKey, CFStringRef inPortKey,
+                                       CFStringRef *outProxyHost, int *ioProxyPort) {
     /* See if the proxy is enabled. */
     CFNumberRef cf_enabled = CFDictionaryGetValue(inDict, inEnabledKey);
     if (cf_enabled == NULL) {