Skip to content

Commit d7ef3ac

Browse files
fmeumkevinjwalls
authored andcommitted
8345684: OperatingSystemMXBean.getSystemCpuLoad() throws NPE
Reviewed-by: dholmes, kevinw, sgehwolf
1 parent 830173f commit d7ef3ac

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/jdk.management/unix/classes/com/sun/management/internal/OperatingSystemImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,13 @@ public double getProcessCpuLoad() {
274274
}
275275

276276
private boolean isCpuSetSameAsHostCpuSet() {
277-
if (containerMetrics != null && containerMetrics.getCpuSetCpus() != null) {
278-
return containerMetrics.getCpuSetCpus().length == getHostOnlineCpuCount0();
277+
if (containerMetrics != null) {
278+
// The return value may change (including from non-null to null) and
279+
// the call may involve I/O, so keep the result in a local variable.
280+
int[] cpuSetCpus = containerMetrics.getCpuSetCpus();
281+
if (cpuSetCpus != null) {
282+
return cpuSetCpus.length == getHostOnlineCpuCount0();
283+
}
279284
}
280285
return false;
281286
}

0 commit comments

Comments
 (0)