Fix: NPE on OS support check

This commit is contained in:
harlekin
2025-01-11 18:12:25 +00:00
committed by Sheepit Renderfarm
parent 00bb8b2b1e
commit a4b670ad8f
2 changed files with 19 additions and 11 deletions

View File

@@ -40,7 +40,7 @@ dependencies {
implementation 'args4j:args4j:2.33'
implementation 'net.lingala.zip4j:zip4j:2.11.+'
implementation 'net.java.dev.jna:jna-platform:5.12.+'
implementation 'com.github.oshi:oshi-core:6.2.+'
implementation 'com.github.oshi:oshi-core:6.6.+'
implementation 'org.simpleframework:simple-xml:2.7.+'
implementation 'com.formdev:flatlaf:2.2' // 2.3+ causes illegal reflective access warning on win + adoptium java 11.0.16
implementation 'com.squareup.okhttp3:okhttp:4.12.+'

View File

@@ -27,6 +27,7 @@ import com.sheepit.client.logger.Log;
import com.sheepit.client.os.windows.Kernel32Lib;
import com.sheepit.client.os.windows.WinProcess;
import com.sun.jna.Native;
import oshi.software.os.OperatingSystem;
public class Windows extends OS {
@@ -81,24 +82,25 @@ public class Windows extends OS {
}
@Override public boolean isSupported() {
long buildNumber = Long.MIN_VALUE;
long buildNumber;
String arch = System.getProperty("os.arch").toLowerCase();
try {
buildNumber = Long.parseLong(operatingSystem.getVersionInfo().getBuildNumber());
}
catch(NumberFormatException e) {
System.err.println("Windows::isSupported Failed to extract Windows build number: " + e);
}
catch (NullPointerException e) {
System.err.println("Windows::isSupported Failed to extract Windows build number: " + e);
var versionInfo = operatingSystem.getVersionInfo();
catch (NumberFormatException | NullPointerException e) {
Log.getInstance().error("Windows::isSupported Failed to extract Windows build number: " + e);
OperatingSystem.OSVersionInfo versionInfo = null;
try {
versionInfo = operatingSystem.getVersionInfo();
}
catch (NullPointerException e1) {
Log.getInstance().error("Windows::isSupported Failed to create versionInfo object: " + e1);
}
if (versionInfo == null) {
return false;
}
else {
String ver = versionInfo.getVersion();
List<String> supportedVersions = List.of("8.1", "10", "11", "Server 2016", "Server 2012 R2", "Server 2019", "Server 2022");
return super.isSupported() && supportedVersions.contains(ver);
return super.isSupported() && checkMajorOSVersionSupport(versionInfo);
}
}
return
@@ -111,6 +113,12 @@ public class Windows extends OS {
);
}
private boolean checkMajorOSVersionSupport(OperatingSystem.OSVersionInfo versionInfo) {
String ver = versionInfo.getVersion();
List<String> supportedVersions = List.of("8.1", "10", "11", "Server 2016", "Server 2012 R2", "Server 2019", "Server 2022");
return super.isSupported() && supportedVersions.contains(ver);
}
int getPriorityClass(int priority) {
int process_class = WinProcess.PRIORITY_IDLE;
switch (priority) {