From 325cdb7fc5cd2ce1d2c2bf08ca064fb0f7e5a0b8 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Fri, 12 Dec 2025 05:46:33 +0000 Subject: [PATCH] 8373517: Revert the macos Tahoe specific change done in JDK-8359830 Reviewed-by: rriggs, bpb --- .../macosx/native/libjava/java_props_macosx.c | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/src/java.base/macosx/native/libjava/java_props_macosx.c b/src/java.base/macosx/native/libjava/java_props_macosx.c index 6656bf04efc..94749ee3efe 100644 --- a/src/java.base/macosx/native/libjava/java_props_macosx.c +++ b/src/java.base/macosx/native/libjava/java_props_macosx.c @@ -23,7 +23,6 @@ * questions. */ -#include #include #include #include @@ -230,50 +229,33 @@ void setOSNameAndVersion(java_props_t *sprops) { NSString *nsVerStr = NULL; char* osVersionCStr = NULL; NSOperatingSystemVersion osVer = [[NSProcessInfo processInfo] operatingSystemVersion]; - // Some macOS versions require special handling. For example, - // when the NSOperatingSystemVersion reports 10.16 as the version - // then it should be treated as 11. Similarly, when it reports 16.0 - // as the version then it should be treated as 26. - // If the SYSTEM_VERSION_COMPAT environment variable (a macOS construct) - // is set to 1, then we don't do any special handling for any versions - // and just literally use the value that NSOperatingSystemVersion reports. - const char* envVal = getenv("SYSTEM_VERSION_COMPAT"); - const bool versionCompatEnabled = envVal != NULL - && strncmp(envVal, "1", 1) == 0; - const bool requiresSpecialHandling = - ((long) osVer.majorVersion == 10 && (long) osVer.minorVersion >= 16) - || ((long) osVer.majorVersion == 16 && (long) osVer.minorVersion >= 0); - if (!requiresSpecialHandling || versionCompatEnabled) { - // no special handling - just use the version reported - // by NSOperatingSystemVersion - if (osVer.patchVersion == 0) { - // Omit trailing ".0" + // 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]; + (long)osVer.majorVersion, (long)osVer.minorVersion, (long)osVer.patchVersion]; } } else { - // Requires special handling. We ignore the version reported - // by the NSOperatingSystemVersion API and instead read the - // *real* ProductVersion from - // /System/Library/CoreServices/.SystemVersionPlatform.plist. - // If not found there, then as a last resort we fallback to - // /System/Library/CoreServices/SystemVersion.plist - NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile: - @"/System/Library/CoreServices/.SystemVersionPlatform.plist"]; + // Version 10.16, without explicit env setting of SYSTEM_VERSION_COMPAT + // AKA 11+ Read the *real* ProductVersion from the hidden link to avoid SYSTEM_VERSION_COMPAT + // If not found, fallback below to the SystemVersion.plist + NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : + @"/System/Library/CoreServices/.SystemVersionPlatform.plist"]; if (version != NULL) { - nsVerStr = [version objectForKey: @"ProductVersion"]; + nsVerStr = [version objectForKey : @"ProductVersion"]; } } - // Last resort - fallback to reading the SystemVersion.plist + // Fallback to reading the SystemVersion.plist if (nsVerStr == NULL) { - NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile: - @"/System/Library/CoreServices/SystemVersion.plist"]; + NSDictionary *version = [NSDictionary dictionaryWithContentsOfFile : + @"/System/Library/CoreServices/SystemVersion.plist"]; if (version != NULL) { - nsVerStr = [version objectForKey: @"ProductVersion"]; + nsVerStr = [version objectForKey : @"ProductVersion"]; } }