changeset 57284:3df41c569827

8235403: Further cleanup to test serviceability/sa/ClhsdbCDSCore.java Reviewed-by: iklam, iignatyev
author clanger
date Mon, 09 Dec 2019 15:01:57 +0100
parents 5e94d60e5dd3
children 3009b27660be
files test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java
diffstat 1 files changed, 18 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java	Mon Dec 09 12:46:12 2019 +0000
+++ b/test/hotspot/jtreg/serviceability/sa/ClhsdbCDSCore.java	Mon Dec 09 15:01:57 2019 +0100
@@ -112,35 +112,31 @@
                 if (Platform.isOSX()) {
                     File coresDir = new File("/cores");
                     if (!coresDir.isDirectory()) {
-                        throw new Error("cores is not a directory");
+                        cleanup();
+                        throw new Error(coresDir + " is not a directory");
                     }
                     // the /cores directory is usually not writable on macOS 10.15
-                    final String osVersion = System.getProperty("os.version");
-                    if (osVersion == null) {
-                        throw new Error("Cannot query the 'os.version' property!");
-                    }
                     if (!coresDir.canWrite()) {
-                        if (osVersion.startsWith("10.15")) {
-                            throw new SkippedException("/cores is not writable");
-                        } else {
-                            throw new Error("cores does not have write permissions");
-                        }
+                        cleanup();
+                        throw new SkippedException("Directory \"" + coresDir +
+                            "\" is not writable");
                     }
                 } else if (Platform.isLinux()) {
                     // Check if a crash report tool is installed.
                     File corePatternFile = new File(CORE_PATTERN_FILE_NAME);
-                    Scanner scanner = new Scanner(corePatternFile);
-                    while (scanner.hasNextLine()) {
-                        String line = scanner.nextLine();
-                        line = line.trim();
-                        System.out.println(line);
-                        if (line.startsWith("|")) {
-                            System.out.println(
-                                "\nThis system uses a crash report tool ($cat /proc/sys/kernel/core_pattern).\n" +
-                                "Core files might not be generated. Please reset /proc/sys/kernel/core_pattern\n" +
-                                "to enable core generation. Skipping this test.");
-                            cleanup();
-                            throw new SkippedException("This system uses a crash report tool");
+                    try (Scanner scanner = new Scanner(corePatternFile)) {
+                        while (scanner.hasNextLine()) {
+                            String line = scanner.nextLine();
+                            line = line.trim();
+                            System.out.println(line);
+                            if (line.startsWith("|")) {
+                                System.out.println(
+                                    "\nThis system uses a crash report tool ($cat /proc/sys/kernel/core_pattern).\n" +
+                                    "Core files might not be generated. Please reset /proc/sys/kernel/core_pattern\n" +
+                                    "to enable core generation. Skipping this test.");
+                                cleanup();
+                                throw new SkippedException("This system uses a crash report tool");
+                            }
                         }
                     }
                 }