Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
8253702: BigSur version number reported as 10.16, should be 11.nn
Backport-of: 6675775
  • Loading branch information
Olga Mikhaltsova authored and Yuri Nesterenko committed Oct 21, 2021
1 parent f049318 commit f31939c
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions src/java.base/macosx/native/libjava/java_props_macosx.c
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -247,15 +247,35 @@ void setOSNameAndVersion(java_props_t *sprops) {
[invoke getReturnValue:&osVer];

NSString *nsVerStr;
if (osVer.patchVersion == 0) { // Omit trailing ".0"
nsVerStr = [NSString stringWithFormat:@"%ld.%ld",
(long)osVer.majorVersion, (long)osVer.minorVersion];
// Copy out the char* if running on version other than 10.16 Mac OS (10.16 == 11.x)
// or explicitly requesting version compatibility
if (!((long)osVer.majorVersion == 10 && (long)osVer.minorVersion >= 16) ||
(getenv("SYSTEM_VERSION_COMPAT") != NULL)) {
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]);
} else {
nsVerStr = [NSString stringWithFormat:@"%ld.%ld.%ld",
(long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion];
// Version 10.16, without explicit env setting of SYSTEM_VERSION_COMPAT
// AKA 11.x; compute the version number from the letter in the ProductBuildVersion
NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile :
@"/System/Library/CoreServices/SystemVersion.plist"];
if (version != NULL) {
NSString *nsBuildVerStr = [version objectForKey : @"ProductBuildVersion"];
if (nsBuildVerStr != NULL && nsBuildVerStr.length >= 3) {
int letter = [nsBuildVerStr characterAtIndex:2];
if (letter >= 'B' && letter <= 'Z') {
int vers = letter - 'A' - 1;
asprintf(&osVersionCStr, "11.%d", vers);
}
}
}
}
// Copy out the char*
osVersionCStr = strdup([nsVerStr UTF8String]);
}
// Fallback if running on pre-10.9 Mac OS
if (osVersionCStr == NULL) {
Expand Down

1 comment on commit f31939c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.