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
--- 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]);
}