changeset 12402:f2224562befb

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
author bchristi
date Thu, 21 Jul 2016 13:02:35 -0700
parents fe2d711d85ae
children cad679416e42
files src/solaris/native/java/lang/java_props_macosx.c
diffstat 1 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/solaris/native/java/lang/java_props_macosx.c	Thu Jun 30 10:13:30 2016 -0700
+++ b/src/solaris/native/java/lang/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]);
     }