Skip to content

Commit 33284cc

Browse files
committed
8345684: OperatingSystemMXBean.getSystemCpuLoad() throws NPE
Backport-of: d7ef3ac0b7e677c4901c69ad4361b5de8408e8d3
1 parent 185e84d commit 33284cc

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

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
@@ -282,8 +282,13 @@ public double getProcessCpuLoad() {
282282
}
283283

284284
private boolean isCpuSetSameAsHostCpuSet() {
285-
if (containerMetrics != null && containerMetrics.getCpuSetCpus() != null) {
286-
return containerMetrics.getCpuSetCpus().length == getHostOnlineCpuCount0();
285+
if (containerMetrics != null) {
286+
// The return value may change (including from non-null to null) and
287+
// the call may involve I/O, so keep the result in a local variable.
288+
int[] cpuSetCpus = containerMetrics.getCpuSetCpus();
289+
if (cpuSetCpus != null) {
290+
return cpuSetCpus.length == getHostOnlineCpuCount0();
291+
}
287292
}
288293
return false;
289294
}

0 commit comments

Comments
 (0)