8181820: jdk/test/lib/Platform should not depend on jdk/test/lib/Utils
authorepavlova
Mon, 12 Jun 2017 12:39:26 -0700
changeset 45453 e72b2abd7f92
parent 45452 6441bc616904
child 45455 31045970cc45
8181820: jdk/test/lib/Platform should not depend on jdk/test/lib/Utils Reviewed-by: alanb, chegar
test/lib/jdk/test/lib/Platform.java
--- a/test/lib/jdk/test/lib/Platform.java	Fri Jun 09 21:34:34 2017 +0000
+++ b/test/lib/jdk/test/lib/Platform.java	Mon Jun 12 12:39:26 2017 -0700
@@ -23,6 +23,10 @@
 
 package jdk.test.lib;
 
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.regex.Pattern;
 
 public class Platform {
@@ -228,7 +232,7 @@
     public static boolean canPtraceAttachLinux() throws Exception {
 
         // SELinux deny_ptrace:
-        String deny_ptrace = Utils.fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
+        String deny_ptrace = fileAsString("/sys/fs/selinux/booleans/deny_ptrace");
         if (deny_ptrace != null && deny_ptrace.contains("1")) {
             // ptrace will be denied:
             return false;
@@ -239,7 +243,7 @@
         // 1 - restricted ptrace: a process must be a children of the inferior or user is root
         // 2 - only processes with CAP_SYS_PTRACE may use ptrace or user is root
         // 3 - no attach: no processes may use ptrace with PTRACE_ATTACH
-        String ptrace_scope = Utils.fileAsString("/proc/sys/kernel/yama/ptrace_scope");
+        String ptrace_scope = fileAsString("/proc/sys/kernel/yama/ptrace_scope");
         if (ptrace_scope != null) {
             if (ptrace_scope.startsWith("3")) {
                 return false;
@@ -265,4 +269,10 @@
                       .matcher(osArch)
                       .matches();
     }
+
+    private static String fileAsString(String filename) throws IOException {
+        Path filePath = Paths.get(filename);
+        if (!Files.exists(filePath)) return null;
+        return new String(Files.readAllBytes(filePath));
+    }
 }