7065902: (file) test/java/nio/file/Files/Misc.java fails on Solaris 11 when run as root
authordxu
Thu, 21 Nov 2013 14:16:49 -0800
changeset 21839 31c719abe9ec
parent 21838 72472170840d
child 21840 394835b0d057
7065902: (file) test/java/nio/file/Files/Misc.java fails on Solaris 11 when run as root Reviewed-by: alanb
jdk/test/java/nio/file/Files/Misc.java
--- a/jdk/test/java/nio/file/Files/Misc.java	Thu Nov 21 11:58:51 2013 -0800
+++ b/jdk/test/java/nio/file/Files/Misc.java	Thu Nov 21 14:16:49 2013 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2013, 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
@@ -313,8 +313,14 @@
                 acl.add(0, entry);
                 view.setAcl(acl);
                 try {
-                    assertTrue(!isWritable(file));
-                    assertTrue(!isExecutable(file));
+                    if (isRoot()) {
+                        // root has all permissions
+                        assertTrue(isWritable(file));
+                        assertTrue(isExecutable(file));
+                    } else {
+                        assertTrue(!isWritable(file));
+                        assertTrue(!isExecutable(file));
+                    }
                 } finally {
                     // Restore ACL
                     acl.remove(0);
@@ -353,4 +359,12 @@
         if (!okay)
             throw new RuntimeException("Assertion Failed");
     }
+
+    private static boolean isRoot() {
+        if (System.getProperty("os.name").startsWith("Windows"))
+            return false;
+
+        Path passwd = Paths.get("/etc/passwd");
+        return Files.isWritable(passwd);
+    }
 }