8161039: System.getProperty("os.version") returns incorrect version number on Mac
authorbchristi
Thu, 21 Jul 2016 13:02:35 -0700
changeset 39765 c1aee33ef0c0
parent 39764 4c2a4f338444
child 39766 745f165bedee
8161039: System.getProperty("os.version") returns incorrect version number on Mac Summary: Omit trailing .0 from os.version when patchVersion is 0 Reviewed-by: alanb
jdk/src/java.base/macosx/native/libjava/java_props_macosx.c
--- a/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jul 21 17:13:23 2016 +0000
+++ b/jdk/src/java.base/macosx/native/libjava/java_props_macosx.c	Thu Jul 21 13:02:35 2016 -0700
@@ -177,8 +177,14 @@
         OSVerStruct (*procInfoFn)(id rec, SEL sel) = (OSVerStruct(*)(id, SEL))objc_msgSend_stret;
         OSVerStruct osVer = procInfoFn([NSProcessInfo processInfo],
                                        @selector(operatingSystemVersion));
-        NSString *nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
-                (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion];
+        NSString *nsVerStr;
+        if (osVer.patchVersion == 0) { // Omit trailing ".0"
+            nsVerStr = [NSString stringWithFormat:@"%ld.%ld",
+                    (long)osVer.majorVersion, (long)osVer.minorVersion];
+        } else {
+            nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
+                    (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion];
+        }
         // Copy out the char*
         osVersionCStr = strdup([nsVerStr UTF8String]);
     }