--- old/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java 2020-01-09 20:39:21.578148107 +0100 +++ new/test/lib/jdk/test/lib/containers/cgroup/MetricsTesterCgroupV1.java 2020-01-09 20:39:21.439147961 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -126,6 +126,9 @@ startUserVal = metrics.getCpuUserUsage(); startUsage = metrics.getCpuUsage(); startPerCpu = metrics.getPerCpuUsage(); + if (startPerCpu == null) { + startPerCpu = new long[0]; + } try { Stream lines = Files.lines(Paths.get("/proc/self/mountinfo")); @@ -149,13 +152,13 @@ return new Scanner(new File(fname)).useDelimiter("\\Z").next(); } catch (FileNotFoundException e) { System.err.println("Unable to open : " + fname); - return ""; + return null; } } private static long getLongValueFromFile(Controller subSystem, String fileName) { String data = getFileContents(subSystem, fileName); - return data.isEmpty() ? 0L : convertStringToLong(data); + return (data == null || data.isEmpty()) ? 0L : convertStringToLong(data); } private static long convertStringToLong(String strval) { @@ -332,11 +335,17 @@ warn(Controller.CPUACCT, "cpuacct.usage", oldVal, newVal); } - Long[] newVals = Stream.of(getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu") + String newValsStr = getFileContents(Controller.CPUACCT, "cpuacct.usage_percpu"); + Long[] newVals = new Long[0]; + if (newValsStr != null) { + newVals = Stream.of(newValsStr .split("\\s+")) .map(Long::parseLong) .toArray(Long[]::new); - Long[] oldVals = LongStream.of(metrics.getPerCpuUsage()).boxed().toArray(Long[]::new); + } + long[] oldValsPrim = metrics.getPerCpuUsage(); + Long[] oldVals = LongStream.of(oldValsPrim == null ? new long[0] : oldValsPrim) + .boxed().toArray(Long[]::new); for (int i = 0; i < oldVals.length; i++) { if (!CgroupMetricsTester.compareWithErrorMargin(oldVals[i], newVals[i])) { warn(Controller.CPUACCT, "cpuacct.usage_percpu", oldVals[i], newVals[i]); @@ -488,6 +497,9 @@ long newUserVal = metrics.getCpuUserUsage(); long newUsage = metrics.getCpuUsage(); long[] newPerCpu = metrics.getPerCpuUsage(); + if (newPerCpu == null) { + newPerCpu = new long[0]; + } // system/user CPU usage counters may be slowly increasing. // allow for equal values for a pass