8031067: java/util/concurrent/atomic/AtomicUpdaters.java: java.lang.Error: Unexpected reflective access
authorchegar
Tue, 07 Jan 2014 11:34:59 +0000
changeset 22113 e32fa2c54c46
parent 22112 4be0c49bc0c5
child 22115 27bd4fa78407
8031067: java/util/concurrent/atomic/AtomicUpdaters.java: java.lang.Error: Unexpected reflective access Summary: Ensure that the test is not influenced by the default users policy. Reviewed-by: martin
jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java
--- a/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java	Tue Jan 07 11:33:22 2014 +0100
+++ b/jdk/test/java/util/concurrent/atomic/AtomicUpdaters.java	Tue Jan 07 11:34:59 2014 +0000
@@ -33,7 +33,7 @@
  */
 import java.util.concurrent.atomic.*;
 import java.lang.reflect.*;
-import java.security.AccessControlException;
+import java.security.*;
 
 public class  AtomicUpdaters {
     enum TYPE { INT, LONG, REF }
@@ -102,6 +102,8 @@
                 verbose = true;
             }
             else if ("UseSM".equals(arg)) {
+                // Ensure that the test is not influenced by the default users policy.
+                Policy.setPolicy(new NoPermissionsPolicy());
                 SecurityManager m = System.getSecurityManager();
                 if (m != null)
                     throw new RuntimeException("No security manager should initially be installed");
@@ -186,4 +188,24 @@
             throw new Error("Some tests failed - see previous stacktraces");
         }
     }
+
+    /**
+     * Policy with no permissions.
+     */
+    private static class NoPermissionsPolicy extends Policy {
+        @Override
+        public PermissionCollection getPermissions(CodeSource cs) {
+            return Policy.UNSUPPORTED_EMPTY_COLLECTION;
+        }
+
+        @Override
+        public PermissionCollection getPermissions(ProtectionDomain pd) {
+            return Policy.UNSUPPORTED_EMPTY_COLLECTION;
+        }
+
+        @Override
+        public boolean implies(ProtectionDomain pd, Permission p) {
+            return Policy.UNSUPPORTED_EMPTY_COLLECTION.implies(p);
+        }
+    }
 }