--- /home/cpdev/src/classpath/java/security/AccessControlContext.java	2005-07-02 21:03:38.000000000 +0000
+++ java/security/AccessControlContext.java	2005-06-30 05:34:44.000000000 +0000
@@ -37,8 +37,6 @@
 
 package java.security;
 
-import java.util.HashSet;
-
 /**
  * AccessControlContext makes system resource access decsion 
  * based on permission rights.  
@@ -55,8 +53,8 @@
  */
 public final class AccessControlContext
 {
-  private final ProtectionDomain[] protectionDomains;
-  private final DomainCombiner combiner;
+  private ProtectionDomain[] protectionDomains;
+  private DomainCombiner combiner;
 
   /**
    * Construct a new AccessControlContext with the specified
@@ -67,12 +65,29 @@
    */
   public AccessControlContext(ProtectionDomain[] context)
   {
-    HashSet domains = new HashSet (context.length);
-    for (int i = 0; i < context.length; i++)
-      domains.add (context[i]);
-    protectionDomains = (ProtectionDomain[])
-      domains.toArray (new ProtectionDomain[domains.size()]);
-    combiner = null;
+    int i, j, k, count = context.length, count2 = 0;
+    for (i = 0, j = 0; i < count; i++)
+      {
+	for (k = 0; k < i; k++)
+	  if (context[k] == protectionDomains[i])
+	    break;
+	if (k != i)		//it means previous loop did not complete
+	  continue;
+
+	count2++;
+      }
+
+    protectionDomains = new ProtectionDomain[count2];
+    for (i = 0, j = 0; i < count2; i++)
+      {
+	for (k = 0; k < i; k++)
+	  if (context[k] == protectionDomains[i])
+	    break;
+	if (k != i)		//it means previous loop did not complete
+	  continue;
+
+	protectionDomains[j++] = context[i];
+      }
   }
 
   /**
@@ -84,17 +99,7 @@
   public AccessControlContext(AccessControlContext acc,
 			      DomainCombiner combiner)
   {
-    // XXX check permission to call this.
-    AccessControlContext acc2 = AccessController.getContext();
-    protectionDomains = combiner.combine (acc2.protectionDomains,
-                                          acc.protectionDomains);
-    this.combiner = combiner;
-  }
-
-  AccessControlContext (ProtectionDomain[] domains, AccessControlContext acc,
-                        DomainCombiner combiner)
-  {
-    protectionDomains = combiner.combine (domains, acc.protectionDomains);
+    this(acc.protectionDomains);
     this.combiner = combiner;
   }
 
@@ -118,11 +123,11 @@
    */
   public void checkPermission(Permission perm) throws AccessControlException
   {
-    if (protectionDomains.length == 0)
-      throw new AccessControlException ("permission not granted");
     for (int i = 0; i < protectionDomains.length; i++)
-      if (!protectionDomains[i].implies(perm))
-        throw new AccessControlException ("permission not granted");
+      if (protectionDomains[i].implies(perm) == true)
+	return;
+
+    throw new AccessControlException("Permission not granted");
   }
 
   /**
@@ -144,17 +149,9 @@
 	if (acc.protectionDomains.length != protectionDomains.length)
 	  return false;
 
-        int i, j;
-        for (i = 0; i < protectionDomains.length; i++)
-          {
-            for (j = 0; j < acc.protectionDomains.length; j++)
-              {
-                if (acc.protectionDomains[j].equals (protectionDomains[i]))
-                  break;
-              }
-            if (j == acc.protectionDomains.length)
-              return false;
-          }
+	for (int i = 0; i < protectionDomains.length; i++)
+	  if (acc.protectionDomains[i] != protectionDomains[i])
+	    return false;
         return true;
       }
     return false;
