Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8284977

MetricsTesterCgroupV2.getLongValueEntryFromFile fails when named value doesn't exist

XMLWordPrintable

    • b03

        This is a test bug.

        When running test/jdk/jdk/internal/platform/cgroup/TestCgroupMetrics.java on ubuntu 21.10, this test looks for a named value "nr_periods" in the file /sys/fs/cgroup/..../cpu.stat

        However, if this file exists but doesn't contain this named value, the following code fails:

            private long getLongValueEntryFromFile(String file, String metric) {
                Path filePath = Paths.get(UNIFIED.getPath(), file);
                try {
                    String strVal = Files.lines(filePath).filter(l -> l.startsWith(metric)).collect(Collectors.joining());
                    String[] keyValues = strVal.split("\\s+");
                    String value = keyValues[1]; <<< HERE
                    return convertStringToLong(value);
                } catch (IOException e) {
                    return NOT_AVAILABLE;
                }
            }



        java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
        at jdk.test.lib.containers.cgroup.MetricsTesterCgroupV2.getLongValueEntryFromFile(MetricsTesterCgroupV2.java:125)
        at jdk.test.lib.containers.cgroup.MetricsTesterCgroupV2.testCpuSchedulingMetrics(MetricsTesterCgroupV2.java:324)
        at jdk.test.lib.containers.cgroup.MetricsTester.testAll(MetricsTester.java:59)
        at TestCgroupMetrics.main(TestCgroupMetrics.java:47)
        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
        at java.base/java.lang.reflect.Method.invoke(Method.java:578)
        at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:312)
        at java.base/java.lang.Thread.run(Thread.java:828)

              mbaesken Matthias Baesken
              iklam Ioi Lam
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

                Created:
                Updated:
                Resolved: