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 'args4j:args4j:2.33'
implementation 'net.lingala.zip4j:zip4j:2.11.+' implementation 'net.lingala.zip4j:zip4j:2.11.+'
implementation 'net.java.dev.jna:jna-platform:5.12.+' 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 '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.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.+' 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.Kernel32Lib;
import com.sheepit.client.os.windows.WinProcess; import com.sheepit.client.os.windows.WinProcess;
import com.sun.jna.Native; import com.sun.jna.Native;
import oshi.software.os.OperatingSystem;
public class Windows extends OS { public class Windows extends OS {
@@ -81,24 +82,25 @@ public class Windows extends OS {
} }
@Override public boolean isSupported() { @Override public boolean isSupported() {
long buildNumber = Long.MIN_VALUE; long buildNumber;
String arch = System.getProperty("os.arch").toLowerCase(); String arch = System.getProperty("os.arch").toLowerCase();
try { try {
buildNumber = Long.parseLong(operatingSystem.getVersionInfo().getBuildNumber()); buildNumber = Long.parseLong(operatingSystem.getVersionInfo().getBuildNumber());
} }
catch(NumberFormatException e) { catch (NumberFormatException | NullPointerException e) {
System.err.println("Windows::isSupported Failed to extract Windows build number: " + 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);
} }
catch (NullPointerException e) {
System.err.println("Windows::isSupported Failed to extract Windows build number: " + e);
var versionInfo = operatingSystem.getVersionInfo();
if (versionInfo == null) { if (versionInfo == null) {
return false; return false;
} }
else { else {
String ver = versionInfo.getVersion(); return super.isSupported() && checkMajorOSVersionSupport(versionInfo);
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 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 getPriorityClass(int priority) {
int process_class = WinProcess.PRIORITY_IDLE; int process_class = WinProcess.PRIORITY_IDLE;
switch (priority) { switch (priority) {