Initial load
diff --git a/test/java/security/ProtectionDomain/AllPerm.jar b/test/java/security/ProtectionDomain/AllPerm.jar
new file mode 100644
index 0000000..430610f
--- /dev/null
+++ b/test/java/security/ProtectionDomain/AllPerm.jar
Binary files differ
diff --git a/test/java/security/ProtectionDomain/AllPerm.java b/test/java/security/ProtectionDomain/AllPerm.java
new file mode 100644
index 0000000..56d8f2d
--- /dev/null
+++ b/test/java/security/ProtectionDomain/AllPerm.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6256734
+ * @summary ProtectionDomain could optimize implies by first checking for
+ *          AllPermission in internal collection
+ */
+
+import java.io.*;
+import java.net.*;
+import java.security.*;
+import java.lang.reflect.*;
+
+public class AllPerm {
+
+    private static final Class[] ARGS = new Class[] { };
+    private static ProtectionDomain allPermClassDomain;
+
+    public static void main(String[]args) throws Exception {
+
+        // create custom class loader that assigns AllPermission to
+        // classes it loads
+
+        File file = new File(System.getProperty("test.src"), "AllPerm.jar");
+        URL[] urls = new URL[] { file.toURL() };
+        ClassLoader parent = Thread.currentThread().getContextClassLoader();
+        AllPermLoader loader = new AllPermLoader(urls, parent);
+
+        // load a class from AllPerm.jar using custom loader
+
+        Object o = loader.loadClass("AllPermClass").newInstance();
+        Method doCheck = o.getClass().getMethod("doCheck", ARGS);
+        allPermClassDomain = o.getClass().getProtectionDomain();
+
+        // set a custom Policy and set the SecurityManager
+
+        Policy.setPolicy(new AllPermPolicy());
+        System.setSecurityManager(new SecurityManager());
+
+        // invoke method on loaded class, which will perform a
+        // security-sensitive operation.  custom policy will check
+        // to see if it is called (it should not be called)
+
+        doCheck.invoke(o, ARGS);
+    }
+
+    /**
+     * this class loader assigns AllPermission to classes that it loads
+     */
+    private static class AllPermLoader extends URLClassLoader {
+
+        public AllPermLoader(URL[] urls, ClassLoader parent) {
+            super(urls, parent);
+        }
+
+        protected PermissionCollection getPermissions(CodeSource codesource) {
+            Permissions perms = new Permissions();
+            perms.add(new AllPermission());
+            return perms;
+        }
+    }
+
+    /**
+     * this policy should not be called if domain is allPermClassDomain
+     */
+    private static class AllPermPolicy extends Policy {
+        public boolean implies(ProtectionDomain domain, Permission permission) {
+            if (domain == allPermClassDomain) {
+                throw new SecurityException
+                        ("Unexpected call into AllPermPolicy");
+            }
+            return true;
+        }
+    }
+}
+
+/**
+ * here is the source code for AllPermClass inside AllPerm.jar
+ */
+/*
+public class AllPermClass {
+    public void doCheck() {
+        System.getProperty("user.name");
+    }
+}
+*/
diff --git a/test/java/security/ProtectionDomain/CheckWhatYouGet.java b/test/java/security/ProtectionDomain/CheckWhatYouGet.java
new file mode 100644
index 0000000..0ac9d32
--- /dev/null
+++ b/test/java/security/ProtectionDomain/CheckWhatYouGet.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2003 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+/*
+ * @test
+ * @author Gary Ellison
+ * @bug 4391927
+ * @summary RMI regression tests failing due to new behavior in ProtectionDomain
+ */
+
+import java.util.Enumeration;
+import java.security.*;
+
+public class CheckWhatYouGet {
+    public static void main(String[] args) throws Exception {
+
+        CodeSource codesource =
+            new CodeSource(null, (java.security.cert.Certificate[]) null);
+        Permissions perms = null;
+        ProtectionDomain pd = new ProtectionDomain(codesource, perms);
+
+        // this should return null
+        if (pd.getPermissions() != null) {
+            System.err.println("TEST FAILED: incorrect Permissions returned");
+            throw new RuntimeException("test failed: incorrect Permissions returned");
+        }
+
+        perms = new Permissions();
+        pd = new ProtectionDomain(codesource, perms);
+        PermissionCollection pc = pd.getPermissions();
+        Enumeration e = pc.elements();
+
+        if (e.hasMoreElements()) {
+            System.err.println("TEST FAILED: incorrect Permissions returned");
+            throw new RuntimeException("test failed: incorrect Permissions returned");
+
+        }
+    }
+}
diff --git a/test/java/security/ProtectionDomain/NullPerms.java b/test/java/security/ProtectionDomain/NullPerms.java
new file mode 100644
index 0000000..2ef7892
--- /dev/null
+++ b/test/java/security/ProtectionDomain/NullPerms.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 1998-2003 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4106012
+ * @summary Make sure passing in a null permissions object is allowed
+ */
+
+import java.security.*;
+
+public class NullPerms {
+
+    public static void main(String[]args) throws Exception {
+        try {
+            CodeSource cs =
+                new CodeSource(null, (java.security.cert.Certificate[]) null);
+            ProtectionDomain pd = new ProtectionDomain(cs, null);
+            if (pd.implies(new SecurityPermission("foo"))) {
+                throw new Exception("implies should return false");
+            }
+        } catch (NullPointerException npe) {
+            throw new Exception("should not have caught an exception");
+        }
+    }
+}
diff --git a/test/java/security/ProtectionDomain/Recursion.java b/test/java/security/ProtectionDomain/Recursion.java
new file mode 100644
index 0000000..d85f648
--- /dev/null
+++ b/test/java/security/ProtectionDomain/Recursion.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2003 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4947618
+ * @summary Recursion problem in security manager and policy code
+ *
+ * @run main/othervm/policy=Recursion.policy Recursion
+ */
+
+import java.net.*;
+import java.security.*;
+
+public class Recursion {
+
+    public static void main(String[] args) throws Exception {
+
+        // trigger security check to make sure policy is set
+        try {
+            System.getProperty("foo.bar");
+        } catch (Exception e) {
+            // fall thru
+        }
+
+        // static perms
+        Permissions staticPerms = new Permissions();
+        staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));
+
+        ProtectionDomain pd = new ProtectionDomain
+                        (new CodeSource
+                                (new URL("http://foo"),
+                                (java.security.cert.Certificate[])null),
+                        staticPerms,
+                        null,
+                        null);
+
+        // test with no SecurityManager
+        //
+        // merging should have occured - check for policy merged.foo permission
+
+        System.setSecurityManager(null);
+        if (pd.toString().indexOf("merged.foo") < 0) {
+            throw new Exception("Test without SecurityManager failed");
+        }
+
+        // test with SecurityManager on the bootclasspath, debug turned off,
+        // getPolicyPermission granted
+        //
+        // merging should have occured - check for policy merged.foo permission
+
+        ProtectionDomain pd2 = new ProtectionDomain
+                        (new CodeSource
+                                (new URL("http://bar"),
+                                (java.security.cert.Certificate[])null),
+                        staticPerms,
+                        null,
+                        null);
+
+        System.setSecurityManager(new SecurityManager());
+        if (pd2.toString().indexOf("merged.foo") < 0) {
+            throw new Exception("Test with bootclass SecurityManager failed");
+        }
+    }
+}
diff --git a/test/java/security/ProtectionDomain/Recursion.policy b/test/java/security/ProtectionDomain/Recursion.policy
new file mode 100644
index 0000000..732c893
--- /dev/null
+++ b/test/java/security/ProtectionDomain/Recursion.policy
@@ -0,0 +1,6 @@
+grant {
+    permission java.security.SecurityPermission "getPolicy";
+    permission java.lang.RuntimePermission "createSecurityManager";
+    permission java.lang.RuntimePermission "setSecurityManager";
+    permission java.util.PropertyPermission "merged.foo", "read";
+};
diff --git a/test/java/security/ProtectionDomain/RecursionDebug.java b/test/java/security/ProtectionDomain/RecursionDebug.java
new file mode 100644
index 0000000..42b757e
--- /dev/null
+++ b/test/java/security/ProtectionDomain/RecursionDebug.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2003-2004 Sun Microsystems, Inc.  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
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 4947618
+ * @summary Recursion problem in security manager and policy code
+ *
+ * @run main/othervm/policy=Recursion.policy -Djava.security.debug=domain RecursionDebug
+ */
+
+import java.security.*;
+import java.net.*;
+
+public class RecursionDebug {
+
+    // non bootclasspath SecurityManager
+    public static class RecursionSM extends SecurityManager {
+        public void checkPermission(Permission p) {
+            super.checkPermission(p);
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+
+        // trigger security check to make sure policy is set
+        try {
+            System.getProperty("foo.bar");
+        } catch (Exception e) {
+            // fall thru
+        }
+
+        // static perms
+        Permissions staticPerms = new Permissions();
+        staticPerms.add(new java.util.PropertyPermission("static.foo", "read"));
+
+        ProtectionDomain pd = new ProtectionDomain
+                        (new CodeSource
+                                (new URL("http://foo"),
+                                (java.security.cert.Certificate[])null),
+                        staticPerms,
+                        null,
+                        null);
+
+        // test with SecurityManager on the bootclasspath, debug turned on
+        //
+        // merging should have occured - check for policy merged.foo permission
+
+        if (pd.toString().indexOf("merged.foo") < 0) {
+            throw new Exception("Test with bootclass SecurityManager failed");
+        }
+
+        // test with SecurityManager not on bootclasspath, debug turned on
+        //
+        // merging should not have occured, and there should be no recursion
+
+        ProtectionDomain pd2 = new ProtectionDomain
+                        (new CodeSource
+                                (new URL("http://bar"),
+                                (java.security.cert.Certificate[])null),
+                        staticPerms,
+                        null,
+                        null);
+
+        System.setSecurityManager(new RecursionDebug.RecursionSM());
+        if (pd2.toString().indexOf("merged.foo") >= 0) {
+            throw new Exception
+                ("Test with custom non-bootclass SecurityManager failed");
+        }
+
+        System.setSecurityManager(null);
+    }
+}