mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-24 14:34:15 +08:00
Catch the exception that the OperatingSystemMXBean does not exist
This commit is contained in:
parent
d11e22026c
commit
ce31bcc6e0
@ -218,6 +218,7 @@ public enum OperatingSystem {
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Optional<PhysicalMemoryStatus> getPhysicalMemoryStatus() {
|
||||
if (CURRENT_OS == LINUX) {
|
||||
try {
|
||||
@ -246,12 +247,15 @@ public enum OperatingSystem {
|
||||
}
|
||||
}
|
||||
|
||||
java.lang.management.OperatingSystemMXBean bean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
|
||||
if (bean instanceof com.sun.management.OperatingSystemMXBean) {
|
||||
com.sun.management.OperatingSystemMXBean sunBean =
|
||||
(com.sun.management.OperatingSystemMXBean)
|
||||
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
|
||||
return Optional.of(new PhysicalMemoryStatus(sunBean.getTotalPhysicalMemorySize(), sunBean.getFreePhysicalMemorySize()));
|
||||
try {
|
||||
java.lang.management.OperatingSystemMXBean bean = java.lang.management.ManagementFactory.getOperatingSystemMXBean();
|
||||
if (bean instanceof com.sun.management.OperatingSystemMXBean) {
|
||||
com.sun.management.OperatingSystemMXBean sunBean =
|
||||
(com.sun.management.OperatingSystemMXBean)
|
||||
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
|
||||
return Optional.of(new PhysicalMemoryStatus(sunBean.getTotalPhysicalMemorySize(), sunBean.getFreePhysicalMemorySize()));
|
||||
}
|
||||
} catch (NoClassDefFoundError ignored) {
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user