OSDN Git Service

Merge remote-tracking branch 'korg/froyo' into froyo-x86 froyo-x86 android-x86-2.2-r2
authorChih-Wei Huang <cwhuang@linux.org.tw>
Sun, 26 Jun 2011 06:35:28 +0000 (14:35 +0800)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sun, 26 Jun 2011 06:35:28 +0000 (14:35 +0800)
25 files changed:
libcore/concurrent/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
libcore/dalvik/src/main/java/dalvik/system/Zygote.java
libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java
libcore/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java
libcore/security/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
libcore/security/src/test/java/tests/api/javax/security/auth/SubjectTest.java
libcore/security/src/test/java/tests/security/acl/AllTests.java
libcore/security/src/test/java/tests/security/acl/IAclEntryTest.java [deleted file]
libcore/security/src/test/java/tests/security/acl/IAclTest.java [deleted file]
libcore/security/src/test/java/tests/security/acl/IGroupTest.java [deleted file]
libcore/security/src/test/java/tests/security/acl/IOwnerTest.java [deleted file]
libcore/security/src/test/java/tests/security/acl/IPermissionTest.java [deleted file]
libcore/security/src/test/java/tests/security/cert/AllTests.java
libcore/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java
libcore/security/src/test/java/tests/security/cert/PolicyNodeTest.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEntryImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEnumerator.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/GroupImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/OwnerImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PermissionImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PrincipalImpl.java [deleted file]
libcore/support/src/test/java/org/apache/harmony/security/tests/support/cert/PolicyNodeImpl.java [deleted file]
libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
vm/native/dalvik_system_Zygote.c

index f0c8ac6..cce1820 100644 (file)
 /*
- * Written by Doug Lea with assistance from members of JCP JSR-166
- * Expert Group.  Adapted and released, under explicit permission,
- * from JDK ArrayList.java which carries the following copyright:
- *
- * Copyright 1997 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information").  You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
  */
 
 package java.util.concurrent;
-import java.util.*;
-import java.util.concurrent.locks.*;
-import java.lang.reflect.Array;
-
-import sun.misc.Unsafe;
 
-// BEGIN android-note
-// removed link to collections framework docs
-// END android-note
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.ConcurrentModificationException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.NoSuchElementException;
+import java.util.RandomAccess;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
- * A thread-safe variant of {@link java.util.ArrayList} in which all mutative
- * operations (<tt>add</tt>, <tt>set</tt>, and so on) are implemented by
- * making a fresh copy of the underlying array.
- *
- * <p> This is ordinarily too costly, but may be <em>more</em> efficient
- * than alternatives when traversal operations vastly outnumber
- * mutations, and is useful when you cannot or don't want to
- * synchronize traversals, yet need to preclude interference among
- * concurrent threads.  The "snapshot" style iterator method uses a
- * reference to the state of the array at the point that the iterator
- * was created. This array never changes during the lifetime of the
- * iterator, so interference is impossible and the iterator is
- * guaranteed not to throw <tt>ConcurrentModificationException</tt>.
- * The iterator will not reflect additions, removals, or changes to
- * the list since the iterator was created.  Element-changing
- * operations on iterators themselves (<tt>remove</tt>, <tt>set</tt>, and
- * <tt>add</tt>) are not supported. These methods throw
- * <tt>UnsupportedOperationException</tt>.
- *
- * <p>All elements are permitted, including <tt>null</tt>.
- *
- * <p>Memory consistency effects: As with other concurrent
- * collections, actions in a thread prior to placing an object into a
- * {@code CopyOnWriteArrayList}
- * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
- * actions subsequent to the access or removal of that element from
- * the {@code CopyOnWriteArrayList} in another thread.
+ * Implements a {@link java.util.ArrayList} variant that is thread-safe. All
+ * write operation result in a new copy of the underlying data being created.
+ * Iterators reflect the state of the CopyOnWriteArrayList at the time they were
+ * created. They are not updated to reflect subsequent changes to the list. In
+ * addition, these iterators cannot be used for modifying the underlying
+ * CopyOnWriteArrayList.
  *
- * @since 1.5
- * @author Doug Lea
- * @param <E> the type of elements held in this collection
+ * @param <E> the element type
  */
-public class CopyOnWriteArrayList<E>
-    implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
-    private static final long serialVersionUID = 8673264195747942595L;
-
-    /** The lock protecting all mutators */
-    transient final ReentrantLock lock = new ReentrantLock();
+public class CopyOnWriteArrayList<E> implements List<E>, RandomAccess, Cloneable, Serializable {
 
-    /** The array, accessed only via getArray/setArray. */
-    private volatile transient Object[] array;
+    private static final long serialVersionUID = 8673264195747942595L;
 
-    /**
-     * Gets the array.  Non-private so as to also be accessible
-     * from CopyOnWriteArraySet class.
-     */
-    final Object[] getArray() {
-        return array;
-    }
+    private transient volatile E[] arr;
 
     /**
-     * Sets the array.
+     * Lock for the queue write methods
      */
-    final void setArray(Object[] a) {
-        array = a;
-    }
+    private final transient ReentrantLock lock = new ReentrantLock();
 
     /**
-     * Creates an empty list.
+     * Creates a new, empty instance of CopyOnWriteArrayList.
      */
     public CopyOnWriteArrayList() {
-        setArray(new Object[0]);
     }
 
     /**
-     * Creates a list containing the elements of the specified
-     * collection, in the order they are returned by the collection's
-     * iterator.
+     * Creates a new instance of CopyOnWriteArrayList and fills it with the
+     * contents of a given Collection.
      *
-     * @param c the collection of initially held elements
-     * @throws NullPointerException if the specified collection is null
+     * @param c     the collection the elements of which are to be copied into
+     *              the new instance.
      */
     public CopyOnWriteArrayList(Collection<? extends E> c) {
-        Object[] elements = c.toArray();
-        // c.toArray might (incorrectly) not return Object[] (see 6260652)
-        if (elements.getClass() != Object[].class)
-            elements = Java6Arrays.copyOf(elements, elements.length, Object[].class);
-        setArray(elements);
+        this((E[]) c.toArray());
     }
 
     /**
-     * Creates a list holding a copy of the given array.
+     * Creates a new instance of CopyOnWriteArrayList and fills it with the
+     * contents of a given array.
      *
-     * @param toCopyIn the array (a copy of this array is used as the
-     *        internal array)
-     * @throws NullPointerException if the specified array is null
+     * @param array the array the elements of which are to be copied into the
+     *              new instance.
      */
-    public CopyOnWriteArrayList(E[] toCopyIn) {
-        setArray(Java6Arrays.copyOf(toCopyIn, toCopyIn.length, Object[].class));
+    public CopyOnWriteArrayList(E[] array) {
+        int size = array.length;
+        E[] data = newElementArray(size);
+        for (int i = 0; i < size; i++) {
+            data[i] = array[i];
+        }
+        arr = data;
     }
 
-    /**
-     * Returns the number of elements in this list.
-     *
-     * @return the number of elements in this list
-     */
-    public int size() {
-        return getArray().length;
+    public boolean add(E e) {
+        lock.lock();
+        try {
+            E[] data;
+            E[] old = getData();
+            int size = old.length;
+            data = newElementArray(size + 1);
+            System.arraycopy(old, 0, data, 0, size);
+            data[size] = e;
+            setData(data);
+            return true;
+        } finally {
+            lock.unlock();
+        }
     }
 
-    /**
-     * Returns <tt>true</tt> if this list contains no elements.
-     *
-     * @return <tt>true</tt> if this list contains no elements
-     */
-    public boolean isEmpty() {
-        return size() == 0;
+    public void add(int index, E e) {
+        lock.lock();
+        try {
+            E[] data;
+            E[] old = getData();
+            int size = old.length;
+            checkIndexInclusive(index, size);
+            data = newElementArray(size+1);
+            System.arraycopy(old, 0, data, 0, index);
+            data[index] = e;
+            if (size > index) {
+                System.arraycopy(old, index, data, index + 1, size - index);
+            }
+            setData(data);
+        } finally {
+            lock.unlock();
+        }
     }
 
-    /**
-     * Test for equality, coping with nulls.
-     */
-    private static boolean eq(Object o1, Object o2) {
-        return (o1 == null ? o2 == null : o1.equals(o2));
+    public boolean addAll(Collection<? extends E> c) {
+        Iterator it = c.iterator();
+        int ssize = c.size();
+        lock.lock();
+        try {
+            int size = size();
+            E[] data;
+            E[] old = getData();
+            int nSize = size + ssize;
+            data = newElementArray(nSize);
+            System.arraycopy(old, 0, data, 0, size);
+            while (it.hasNext()) {
+                data[size++] = (E) it.next();
+            }
+            setData(data);
+        } finally {
+            lock.unlock();
+        }
+        return true;
     }
 
-    /**
-     * static version of indexOf, to allow repeated calls without
-     * needing to re-acquire array each time.
-     * @param o element to search for
-     * @param elements the array
-     * @param index first index to search
-     * @param fence one past last index to search
-     * @return index of element, or -1 if absent
-     */
-    private static int indexOf(Object o, Object[] elements,
-                               int index, int fence) {
-        if (o == null) {
-            for (int i = index; i < fence; i++)
-                if (elements[i] == null)
-                    return i;
-        } else {
-            for (int i = index; i < fence; i++)
-                if (o.equals(elements[i]))
-                    return i;
+    public boolean addAll(int index, Collection<? extends E> c) {
+        Iterator it = c.iterator();
+        int ssize = c.size();
+        lock.lock();
+        try {
+            int size = size();
+            checkIndexInclusive(index, size);
+            E[] data;
+            E[] old = getData();
+            int nSize = size + ssize;
+            data = newElementArray(nSize);
+            System.arraycopy(old, 0, data, 0, index);
+            int i = index;
+            while (it.hasNext()) {
+                data[i++] = (E) it.next();
+            }
+            if (size > index) {
+                System.arraycopy(old, index, data, index + ssize, size - index);
+            }
+            setData(data);
+        } finally {
+            lock.unlock();
         }
-        return -1;
+        return true;
     }
 
     /**
-     * static version of lastIndexOf.
-     * @param o element to search for
-     * @param elements the array
-     * @param index first index to search
-     * @return index of element, or -1 if absent
+     * Adds to this CopyOnWriteArrayList all those elements from a given
+     * collection that are not yet part of the list.
+     *
+     * @param c     the collection from which the potential new elements are
+     *              taken.
+     *
+     * @return the number of elements actually added to this list.
      */
-    private static int lastIndexOf(Object o, Object[] elements, int index) {
-        if (o == null) {
-            for (int i = index; i >= 0; i--)
-                if (elements[i] == null)
-                    return i;
-        } else {
-            for (int i = index; i >= 0; i--)
-                if (o.equals(elements[i]))
-                    return i;
+    public int addAllAbsent(Collection<? extends E> c) {
+        if (c.size() == 0) {
+            return 0;
+        }
+        lock.lock();
+        try {
+            E[] old = getData();
+            int size = old.length;
+            E[] toAdd = newElementArray(c.size());
+            int i = 0;
+            for (Iterator it = c.iterator(); it.hasNext();) {
+                E o = (E) it.next();
+                if (indexOf(o) < 0) {
+                    toAdd[i++] = o;
+                }
+            }
+            E[] data = newElementArray(size + i);
+            System.arraycopy(old, 0, data, 0, size);
+            System.arraycopy(toAdd, 0, data, size, i);
+            setData(data);
+            return i;
+        } finally {
+            lock.unlock();
         }
-        return -1;
     }
 
     /**
-     * Returns <tt>true</tt> if this list contains the specified element.
-     * More formally, returns <tt>true</tt> if and only if this list contains
-     * at least one element <tt>e</tt> such that
-     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
+     * Adds to this CopyOnWriteArrayList another element, given that this
+     * element is not yet part of the list.
+     *
+     * @param e     the potential new element.
      *
-     * @param o element whose presence in this list is to be tested
-     * @return <tt>true</tt> if this list contains the specified element
+     * @return true if the element was added, or false otherwise.
      */
-    public boolean contains(Object o) {
-        Object[] elements = getArray();
-        return indexOf(o, elements, 0, elements.length) >= 0;
+    public boolean addIfAbsent(E e) {
+        lock.lock();
+        try {
+            E[] data;
+            E[] old = getData();
+            int size = old.length;
+            if (size != 0) {
+                if (indexOf(e) >= 0) {
+                    return false;
+                }
+            }
+            data = newElementArray(size + 1);
+            System.arraycopy(old, 0, data, 0, size);
+            data[size] = e;
+            setData(data);
+            return true;
+        } finally {
+            lock.unlock();
+        }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public int indexOf(Object o) {
-        Object[] elements = getArray();
-        return indexOf(o, elements, 0, elements.length);
+    public void clear() {
+        lock.lock();
+        try {
+            setData(newElementArray(0));
+        } finally {
+            lock.unlock();
+        }
     }
 
-    /**
-     * Returns the index of the first occurrence of the specified element in
-     * this list, searching forwards from <tt>index</tt>, or returns -1 if
-     * the element is not found.
-     * More formally, returns the lowest index <tt>i</tt> such that
-     * <tt>(i&nbsp;&gt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(e==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;e.equals(get(i))))</tt>,
-     * or -1 if there is no such index.
-     *
-     * @param e element to search for
-     * @param index index to start searching from
-     * @return the index of the first occurrence of the element in
-     *         this list at position <tt>index</tt> or later in the list;
-     *         <tt>-1</tt> if the element is not found.
-     * @throws IndexOutOfBoundsException if the specified index is negative
-     */
-    public int indexOf(E e, int index) {
-        Object[] elements = getArray();
-        return indexOf(e, elements, index, elements.length);
+    @Override
+    public Object clone() {
+        try {
+            CopyOnWriteArrayList thisClone = (CopyOnWriteArrayList) super.clone();
+            thisClone.setData(this.getData());
+            return thisClone;
+        } catch (CloneNotSupportedException e) {
+            throw new RuntimeException("CloneNotSupportedException is not expected here");
+        }
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    public int lastIndexOf(Object o) {
-        Object[] elements = getArray();
-        return lastIndexOf(o, elements, elements.length - 1);
+    public boolean contains(Object o) {
+        return indexOf(o) >= 0;
     }
 
-    /**
-     * Returns the index of the last occurrence of the specified element in
-     * this list, searching backwards from <tt>index</tt>, or returns -1 if
-     * the element is not found.
-     * More formally, returns the highest index <tt>i</tt> such that
-     * <tt>(i&nbsp;&lt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(e==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;e.equals(get(i))))</tt>,
-     * or -1 if there is no such index.
-     *
-     * @param e element to search for
-     * @param index index to start searching backwards from
-     * @return the index of the last occurrence of the element at position
-     *         less than or equal to <tt>index</tt> in this list;
-     *         -1 if the element is not found.
-     * @throws IndexOutOfBoundsException if the specified index is greater
-     *         than or equal to the current size of this list
-     */
-    public int lastIndexOf(E e, int index) {
-        Object[] elements = getArray();
-        return lastIndexOf(e, elements, index);
+    public boolean containsAll(Collection<?> c) {
+        E[] data = getData();
+        return containsAll(c, data, 0, data.length);
     }
 
-    /**
-     * Returns a shallow copy of this list.  (The elements themselves
-     * are not copied.)
-     *
-     * @return a clone of this list
-     */
-    public Object clone() {
-        try {
-            CopyOnWriteArrayList c = (CopyOnWriteArrayList)(super.clone());
-            c.resetLock();
-            return c;
-        } catch (CloneNotSupportedException e) {
-            // this shouldn't happen, since we are Cloneable
-            throw new InternalError();
+    public boolean equals(Object o) {
+        if (o == this) {
+            return true;
+        }
+        if (!(o instanceof List)) {
+            return false;
+        }
+        List l = (List) o;
+        Iterator it = l.listIterator();
+        Iterator ourIt = listIterator();
+        while (it.hasNext()) {
+            if (!ourIt.hasNext()) {
+                return false;
+            }
+            Object thisListElem = it.next();
+            Object anotherListElem = ourIt.next();
+            if (!(thisListElem == null ? anotherListElem == null : thisListElem
+                    .equals(anotherListElem))) {
+                return false;
+            }
         }
+        if (ourIt.hasNext()) {
+            return false;
+        }
+        return true;
+    }
+
+    public E get(int index) {
+        E[] data = getData();
+        return data[index];
+    }
+
+    public int hashCode() {
+        int hashCode = 1;
+        Iterator it = listIterator();
+        while (it.hasNext()) {
+            Object obj = it.next();
+            hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
+        }
+        return hashCode;
     }
 
     /**
-     * Returns an array containing all of the elements in this list
-     * in proper sequence (from first to last element).
+     * Returns the index of a given element, starting the search from a given
+     * position in the list.
      *
-     * <p>The returned array will be "safe" in that no references to it are
-     * maintained by this list.  (In other words, this method must allocate
-     * a new array).  The caller is thus free to modify the returned array.
+     * @param e     the element to search.
+     * @param index the index at which to start the search.
      *
-     * <p>This method acts as bridge between array-based and collection-based
-     * APIs.
-     *
-     * @return an array containing all the elements in this list
+     * @return the index of the element or null, if the element has not been
+     * found at or beyond the given start index.
      */
-    public Object[] toArray() {
-        Object[] elements = getArray();
-        return Java6Arrays.copyOf(elements, elements.length);
+    public int indexOf(E e, int index) {
+        E[] data = getData();
+        return indexOf(e, data, index, data.length - index);
+    }
+
+    public int indexOf(Object o) {
+        E[] data = getData();
+        return indexOf(o, data, 0, data.length);
+    }
+
+    public boolean isEmpty() {
+        return size() == 0;
+    }
+
+    public Iterator<E> iterator() {
+        return new ListIteratorImpl(getData(), 0);
     }
 
     /**
-     * Returns an array containing all of the elements in this list in
-     * proper sequence (from first to last element); the runtime type of
-     * the returned array is that of the specified array.  If the list fits
-     * in the specified array, it is returned therein.  Otherwise, a new
-     * array is allocated with the runtime type of the specified array and
-     * the size of this list.
-     *
-     * <p>If this list fits in the specified array with room to spare
-     * (i.e., the array has more elements than this list), the element in
-     * the array immediately following the end of the list is set to
-     * <tt>null</tt>.  (This is useful in determining the length of this
-     * list <i>only</i> if the caller knows that this list does not contain
-     * any null elements.)
-     *
-     * <p>Like the {@link #toArray()} method, this method acts as bridge between
-     * array-based and collection-based APIs.  Further, this method allows
-     * precise control over the runtime type of the output array, and may,
-     * under certain circumstances, be used to save allocation costs.
+     * Returns the last index of a given element, starting the search from
+     * a given position in the list and going backwards.
      *
-     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
-     * The following code can be used to dump the list into a newly
-     * allocated array of <tt>String</tt>:
+     * @param e     the element to search.
+     * @param index the index at which to start the search.
      *
-     * <pre>
-     *     String[] y = x.toArray(new String[0]);</pre>
-     *
-     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
-     * <tt>toArray()</tt>.
-     *
-     * @param a the array into which the elements of the list are to
-     *          be stored, if it is big enough; otherwise, a new array of the
-     *          same runtime type is allocated for this purpose.
-     * @return an array containing all the elements in this list
-     * @throws ArrayStoreException if the runtime type of the specified array
-     *         is not a supertype of the runtime type of every element in
-     *         this list
-     * @throws NullPointerException if the specified array is null
+     * @return the index of the element or null, if the element has not been
+     * found at or before the given start index.
      */
-    @SuppressWarnings("unchecked")
-    public <T> T[] toArray(T a[]) {
-        Object[] elements = getArray();
-        int len = elements.length;
-        if (a.length < len)
-            return (T[]) Java6Arrays.copyOf(elements, len, a.getClass());
-        else {
-            System.arraycopy(elements, 0, a, 0, len);
-            if (a.length > len)
-                a[len] = null;
-            return a;
-        }
+    public int lastIndexOf(E e, int index) {
+        E[] data = getData();
+        return lastIndexOf(e, data, 0, index);
     }
 
-    // Positional Access Operations
+    public int lastIndexOf(Object o) {
+        E[] data = getData();
+        return lastIndexOf(o, data, 0, data.length);
+    }
 
-    @SuppressWarnings("unchecked")
-    private E get(Object[] a, int index) {
-        return (E) a[index];
+    public ListIterator<E> listIterator() {
+        return new ListIteratorImpl(getData(), 0);
     }
 
-    /**
-     * {@inheritDoc}
-     *
-     * @throws IndexOutOfBoundsException {@inheritDoc}
-     */
-    public E get(int index) {
-        return get(getArray(), index);
+    public ListIterator<E> listIterator(int index) {
+        E[] data = getData();
+        checkIndexInclusive(index, data.length);
+        return new ListIteratorImpl(data, index);
     }
 
-    /**
-     * Replaces the element at the specified position in this list with the
-     * specified element.
-     *
-     * @throws IndexOutOfBoundsException {@inheritDoc}
-     */
-    public E set(int index, E element) {
-        final ReentrantLock lock = this.lock;
+    public E remove(int index) {
+        return removeRange(index, 1);
+    }
+
+    public boolean remove(Object o) {
         lock.lock();
         try {
-            Object[] elements = getArray();
-            E oldValue = get(elements, index);
-
-            if (oldValue != element) {
-                int len = elements.length;
-                Object[] newElements = Java6Arrays.copyOf(elements, len);
-                newElements[index] = element;
-                setArray(newElements);
-            } else {
-                // Not quite a no-op; ensures volatile write semantics
-                setArray(elements);
+            int index = indexOf(o);
+            if (index == -1) {
+                return false;
             }
-            return oldValue;
+            remove(index);
+            return true;
         } finally {
             lock.unlock();
         }
     }
 
-    /**
-     * Appends the specified element to the end of this list.
-     *
-     * @param e element to be appended to this list
-     * @return <tt>true</tt> (as specified by {@link Collection#add})
-     */
-    public boolean add(E e) {
-        final ReentrantLock lock = this.lock;
+    public boolean removeAll(Collection<?> c) {
         lock.lock();
         try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            Object[] newElements = Java6Arrays.copyOf(elements, len + 1);
-            newElements[len] = e;
-            setArray(newElements);
-            return true;
+            return removeAll(c, 0, getData().length) != 0;
         } finally {
             lock.unlock();
         }
     }
 
-    /**
-     * Inserts the specified element at the specified position in this
-     * list. Shifts the element currently at that position (if any) and
-     * any subsequent elements to the right (adds one to their indices).
-     *
-     * @throws IndexOutOfBoundsException {@inheritDoc}
-     */
-    public void add(int index, E element) {
-        final ReentrantLock lock = this.lock;
+    public boolean retainAll(Collection<?> c) {
+        if (c == null) {
+            throw new NullPointerException();
+        }
         lock.lock();
         try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (index > len || index < 0)
-                throw new IndexOutOfBoundsException("Index: "+index+
-                                                    ", Size: "+len);
-            Object[] newElements;
-            int numMoved = len - index;
-            if (numMoved == 0)
-                newElements = Java6Arrays.copyOf(elements, len + 1);
-            else {
-                newElements = new Object[len + 1];
-                System.arraycopy(elements, 0, newElements, 0, index);
-                System.arraycopy(elements, index, newElements, index + 1,
-                                 numMoved);
-            }
-            newElements[index] = element;
-            setArray(newElements);
+            return retainAll(c, 0, getData().length) != 0;
         } finally {
             lock.unlock();
         }
     }
 
-    /**
-     * Removes the element at the specified position in this list.
-     * Shifts any subsequent elements to the left (subtracts one from their
-     * indices).  Returns the element that was removed from the list.
-     *
-     * @throws IndexOutOfBoundsException {@inheritDoc}
-     */
-    public E remove(int index) {
-        final ReentrantLock lock = this.lock;
+    public E set(int index, E e) {
         lock.lock();
         try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            E oldValue = get(elements, index);
-            int numMoved = len - index - 1;
-            if (numMoved == 0)
-                setArray(Java6Arrays.copyOf(elements, len - 1));
-            else {
-                Object[] newElements = new Object[len - 1];
-                System.arraycopy(elements, 0, newElements, 0, index);
-                System.arraycopy(elements, index + 1, newElements, index,
-                                 numMoved);
-                setArray(newElements);
-            }
-            return oldValue;
+            int size = size();
+            checkIndexExlusive(index, size);
+            E[] data;
+            data = newElementArray(size);
+            E[] oldArr = getData();
+            System.arraycopy(oldArr, 0, data, 0, size);
+            E old = data[index];
+            data[index] = e;
+            setData(data);
+            return old;
         } finally {
             lock.unlock();
         }
     }
 
-    /**
-     * Removes the first occurrence of the specified element from this list,
-     * if it is present.  If this list does not contain the element, it is
-     * unchanged.  More formally, removes the element with the lowest index
-     * <tt>i</tt> such that
-     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
-     * (if such an element exists).  Returns <tt>true</tt> if this list
-     * contained the specified element (or equivalently, if this list
-     * changed as a result of the call).
-     *
-     * @param o element to be removed from this list, if present
-     * @return <tt>true</tt> if this list contained the specified element
-     */
-    public boolean remove(Object o) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (len != 0) {
-                // Copy while searching for element to remove
-                // This wins in the normal case of element being present
-                int newlen = len - 1;
-                Object[] newElements = new Object[newlen];
-
-                for (int i = 0; i < newlen; ++i) {
-                    if (eq(o, elements[i])) {
-                        // found one;  copy remaining and exit
-                        for (int k = i + 1; k < len; ++k)
-                            newElements[k-1] = elements[k];
-                        setArray(newElements);
-                        return true;
-                    } else
-                        newElements[i] = elements[i];
-                }
+    public int size() {
+        return getData().length;
+    }
 
-                // special handling for last cell
-                if (eq(o, elements[newlen])) {
-                    setArray(newElements);
-                    return true;
-                }
-            }
-            return false;
-        } finally {
-            lock.unlock();
-        }
+    public List<E> subList(int fromIndex, int toIndex) {
+        return new SubList(this, fromIndex, toIndex);
     }
 
-    /**
-     * Removes from this list all of the elements whose index is between
-     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
-     * Shifts any succeeding elements to the left (reduces their index).
-     * This call shortens the list by <tt>(toIndex - fromIndex)</tt> elements.
-     * (If <tt>toIndex==fromIndex</tt>, this operation has no effect.)
-     *
-     * @param fromIndex index of first element to be removed
-     * @param toIndex index after last element to be removed
-     * @throws IndexOutOfBoundsException if fromIndex or toIndex out of range
-     *         (@code{fromIndex < 0 || toIndex > size() || toIndex < fromIndex})
-     */
-    private void removeRange(int fromIndex, int toIndex) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-
-            if (fromIndex < 0 || toIndex > len || toIndex < fromIndex)
-                throw new IndexOutOfBoundsException();
-            int newlen = len - (toIndex - fromIndex);
-            int numMoved = len - toIndex;
-            if (numMoved == 0)
-                setArray(Java6Arrays.copyOf(elements, newlen));
-            else {
-                Object[] newElements = new Object[newlen];
-                System.arraycopy(elements, 0, newElements, 0, fromIndex);
-                System.arraycopy(elements, toIndex, newElements,
-                                 fromIndex, numMoved);
-                setArray(newElements);
-            }
-        } finally {
-            lock.unlock();
-        }
+    public Object[] toArray() {
+        E[] data = getData();
+        return toArray(data, 0, data.length);
     }
 
-    /**
-     * Append the element if not present.
-     *
-     * @param e element to be added to this list, if absent
-     * @return <tt>true</tt> if the element was added
-     */
-    public boolean addIfAbsent(E e) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            // Copy while checking if already present.
-            // This wins in the most common case where it is not present
-            Object[] elements = getArray();
-            int len = elements.length;
-            Object[] newElements = new Object[len + 1];
-            for (int i = 0; i < len; ++i) {
-                if (eq(e, elements[i]))
-                    return false; // exit, throwing away copy
-                else
-                    newElements[i] = elements[i];
-            }
-            newElements[len] = e;
-            setArray(newElements);
-            return true;
-        } finally {
-            lock.unlock();
+    public <T> T[] toArray(T[] a) {
+        E[] data = getData();
+        return (T[]) toArray(a, data, 0, data.length);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder("[");
+
+        Iterator it = listIterator();
+        while (it.hasNext()) {
+            sb.append(String.valueOf(it.next()));
+            sb.append(", ");
         }
+        if (sb.length() > 1) {
+            sb.setLength(sb.length() - 2);
+        }
+        sb.append("]");
+        return sb.toString();
+    }
+
+    // private and package private methods
+
+    @SuppressWarnings("unchecked")
+    private final E[] newElementArray(int size) {
+        return (E[])new Object[size];
     }
 
     /**
-     * Returns <tt>true</tt> if this list contains all of the elements of the
-     * specified collection.
+     * sets the internal data array
      *
-     * @param c collection to be checked for containment in this list
-     * @return <tt>true</tt> if this list contains all of the elements of the
-     *         specified collection
-     * @throws NullPointerException if the specified collection is null
-     * @see #contains(Object)
+     * @param data array to set
      */
-    public boolean containsAll(Collection<?> c) {
-        Object[] elements = getArray();
-        int len = elements.length;
-        for (Object e : c) {
-            if (indexOf(e, elements, 0, len) < 0)
-                return false;
-        }
-        return true;
+    private final void setData(E[] data) {
+        arr = data;
     }
 
     /**
-     * Removes from this list all of its elements that are contained in
-     * the specified collection. This is a particularly expensive operation
-     * in this class because of the need for an internal temporary array.
+     * gets the internal data array (or a new array if it is null)
      *
-     * @param c collection containing elements to be removed from this list
-     * @return <tt>true</tt> if this list changed as a result of the call
-     * @throws ClassCastException if the class of an element of this list
-     *         is incompatible with the specified collection (optional)
-     * @throws NullPointerException if this list contains a null element and the
-     *         specified collection does not permit null elements (optional),
-     *         or if the specified collection is null
-     * @see #remove(Object)
+     * @return the data array
      */
-    public boolean removeAll(Collection<?> c) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (len != 0) {
-                // temp array holds those elements we know we want to keep
-                int newlen = 0;
-                Object[] temp = new Object[len];
-                for (int i = 0; i < len; ++i) {
-                    Object element = elements[i];
-                    if (!c.contains(element))
-                        temp[newlen++] = element;
-                }
-                if (newlen != len) {
-                    setArray(Java6Arrays.copyOf(temp, newlen));
-                    return true;
-                }
-            }
-            return false;
-        } finally {
-            lock.unlock();
+    final E[] getData() {
+        if (arr == null) {
+            return newElementArray(0);
         }
+        return arr;
     }
 
     /**
-     * Retains only the elements in this list that are contained in the
-     * specified collection.  In other words, removes from this list all of
-     * its elements that are not contained in the specified collection.
+     * Removes from the specified range of this list
+     * all the elements that are contained in the specified collection
+     * <p/>
+     * !should be called under lock
      *
-     * @param c collection containing elements to be retained in this list
-     * @return <tt>true</tt> if this list changed as a result of the call
-     * @throws ClassCastException if the class of an element of this list
-     *         is incompatible with the specified collection (optional)
-     * @throws NullPointerException if this list contains a null element and the
-     *         specified collection does not permit null elements (optional),
-     *         or if the specified collection is null
-     * @see #remove(Object)
+     * @return Returns the number of removed elements
      */
-    public boolean retainAll(Collection<?> c) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (len != 0) {
-                // temp array holds those elements we know we want to keep
-                int newlen = 0;
-                Object[] temp = new Object[len];
-                for (int i = 0; i < len; ++i) {
-                    Object element = elements[i];
-                    if (c.contains(element))
-                        temp[newlen++] = element;
-                }
-                if (newlen != len) {
-                    setArray(Java6Arrays.copyOf(temp, newlen));
-                    return true;
-                }
+    final int removeAll(Collection c, int start, int size) {
+        int ssize = c.size();
+        if (ssize == 0) {
+            return 0;
+        }
+        Object[] old = getData();
+        int arrsize = old.length;
+        if (arrsize == 0) {
+            return 0;
+        }
+        Object[] data = new Object[size];
+        int j = 0;
+        for (int i = start; i < (start + size); i++) {
+            if (!c.contains(old[i])) {
+                data[j++] = old[i];
             }
-            return false;
-        } finally {
-            lock.unlock();
         }
+        if (j != size) {
+            E[] result = newElementArray(arrsize - (size - j));
+            System.arraycopy(old, 0, result, 0, start);
+            System.arraycopy(data, 0, result, start, j);
+            System.arraycopy(old, start + size, result, start + j, arrsize
+                    - (start + size));
+            setData(result);
+            return (size - j);
+        }
+        return 0;
     }
 
     /**
-     * Appends all of the elements in the specified collection that
-     * are not already contained in this list, to the end of
-     * this list, in the order that they are returned by the
-     * specified collection's iterator.
+     * Retains only the elements in the specified range of this list
+     * that are contained in the specified collection
      *
-     * @param c collection containing elements to be added to this list
-     * @return the number of elements added
-     * @throws NullPointerException if the specified collection is null
-     * @see #addIfAbsent(Object)
+     * @return Returns the number of removed elements
      */
-    public int addAllAbsent(Collection<? extends E> c) {
-        Object[] cs = c.toArray();
-        if (cs.length == 0)
+    // should be called under lock
+    int retainAll(Collection c, int start, int size) {
+        Object[] old = getData();
+        if (size == 0) {
             return 0;
-        Object[] uniq = new Object[cs.length];
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            int added = 0;
-            for (int i = 0; i < cs.length; ++i) { // scan for duplicates
-                Object e = cs[i];
-                if (indexOf(e, elements, 0, len) < 0 &&
-                    indexOf(e, uniq, 0, added) < 0)
-                    uniq[added++] = e;
+        }
+        if (c.size() == 0) {
+            E[] data;
+            if (size == old.length) {
+                data = newElementArray(0);
+            } else {
+                data = newElementArray(old.length - size);
+                System.arraycopy(old, 0, data, 0, start);
+                System.arraycopy(old, start + size, data, start, old.length
+                        - start - size);
             }
-            if (added > 0) {
-                Object[] newElements = Java6Arrays.copyOf(elements, len + added);
-                System.arraycopy(uniq, 0, newElements, len, added);
-                setArray(newElements);
+            setData(data);
+            return size;
+        }
+        Object[] temp = new Object[size];
+        int pos = 0;
+        for (int i = start; i < (start + size); i++) {
+            if (c.contains(old[i])) {
+                temp[pos++] = old[i];
             }
-            return added;
-        } finally {
-            lock.unlock();
         }
+        if (pos == size) {
+            return 0;
+        }
+        E[] data = newElementArray(pos + old.length - size);
+        System.arraycopy(old, 0, data, 0, start);
+        System.arraycopy(temp, 0, data, start, pos);
+        System.arraycopy(old, start + size, data, start + pos, old.length
+                - start - size);
+        setData(data);
+        return (size - pos);
     }
 
     /**
-     * Removes all of the elements from this list.
-     * The list will be empty after this call returns.
+     * Removes specified range from this list
      */
-    public void clear() {
-        final ReentrantLock lock = this.lock;
+    E removeRange(int start, int size) {
         lock.lock();
         try {
-            setArray(new Object[0]);
+            int sizeArr = size();
+            checkIndexExlusive(start, sizeArr);
+            checkIndexInclusive(start + size, sizeArr);
+            E[] data;
+            data = newElementArray(sizeArr - size);
+            E[] oldArr = getData();
+            System.arraycopy(oldArr, 0, data, 0, start);
+            E old = oldArr[start];
+            if (sizeArr > (start + size)) {
+                System.arraycopy(oldArr, start + size, data, start, sizeArr
+                        - (start + size));
+            }
+            setData(data);
+            return old;
         } finally {
             lock.unlock();
         }
     }
 
+    // some util static functions to use by iterators and methods
     /**
-     * Appends all of the elements in the specified collection to the end
-     * of this list, in the order that they are returned by the specified
-     * collection's iterator.
-     *
-     * @param c collection containing elements to be added to this list
-     * @return <tt>true</tt> if this list changed as a result of the call
-     * @throws NullPointerException if the specified collection is null
-     * @see #add(Object)
+     * Returns an array containing all of the elements
+     * in the specified range of the array in proper sequence
      */
-    public boolean addAll(Collection<? extends E> c) {
-        Object[] cs = c.toArray();
-        if (cs.length == 0)
-            return false;
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            Object[] newElements = Java6Arrays.copyOf(elements, len + cs.length);
-            System.arraycopy(cs, 0, newElements, len, cs.length);
-            setArray(newElements);
-            return true;
-        } finally {
-            lock.unlock();
-        }
+    static Object[] toArray(Object[] data, int start, int size) {
+        Object[] result = new Object[size];
+        System.arraycopy(data, start, result, 0, size);
+        return result;
     }
 
     /**
-     * Inserts all of the elements in the specified collection into this
-     * list, starting at the specified position.  Shifts the element
-     * currently at that position (if any) and any subsequent elements to
-     * the right (increases their indices).  The new elements will appear
-     * in this list in the order that they are returned by the
-     * specified collection's iterator.
-     *
-     * @param index index at which to insert the first element
-     *        from the specified collection
-     * @param c collection containing elements to be added to this list
-     * @return <tt>true</tt> if this list changed as a result of the call
-     * @throws IndexOutOfBoundsException {@inheritDoc}
-     * @throws NullPointerException if the specified collection is null
-     * @see #add(int,Object)
+     * Returns an array containing all of the elements
+     * in the specified range of the array in proper sequence,
+     * stores the result in the array, specified by first parameter
+     * (as for public instance method toArray(Object[] to)
      */
-    public boolean addAll(int index, Collection<? extends E> c) {
-        Object[] cs = c.toArray();
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (index > len || index < 0)
-                throw new IndexOutOfBoundsException("Index: "+index+
-                                                    ", Size: "+len);
-            if (cs.length == 0)
-                return false;
-            int numMoved = len - index;
-            Object[] newElements;
-            if (numMoved == 0)
-                newElements = Java6Arrays.copyOf(elements, len + cs.length);
-            else {
-                newElements = new Object[len + cs.length];
-                System.arraycopy(elements, 0, newElements, 0, index);
-                System.arraycopy(elements, index,
-                                 newElements, index + cs.length,
-                                 numMoved);
+    static Object[] toArray(Object[] to, Object[] data, int start, int size) {
+        int l = data.length;
+        if (to.length < l) {
+            to = (Object[]) Array.newInstance(to.getClass().getComponentType(),
+                    l);
+        } else {
+            if (to.length > l) {
+                to[l] = null;
             }
-            System.arraycopy(cs, 0, newElements, index, cs.length);
-            setArray(newElements);
-            return true;
-        } finally {
-            lock.unlock();
         }
+        System.arraycopy(data, start, to, 0, size);
+        return to;
     }
 
     /**
-     * Save the state of the list to a stream (i.e., serialize it).
+     * Checks if the specified range of the
+     * array contains all of the elements in the collection
      *
-     * @serialData The length of the array backing the list is emitted
-     *               (int), followed by all of its elements (each an Object)
-     *               in the proper order.
-     * @param s the stream
+     * @param c     collection with elements
+     * @param data  array where to search the elements
+     * @param start start index
+     * @param size  size of the range
      */
-    private void writeObject(java.io.ObjectOutputStream s)
-        throws java.io.IOException{
-
-        // Write out element count, and any hidden stuff
-        s.defaultWriteObject();
-
-        Object[] elements = getArray();
-        int len = elements.length;
-        // Write out array length
-        s.writeInt(len);
-
-        // Write out all elements in the proper order.
-        for (int i = 0; i < len; i++)
-            s.writeObject(elements[i]);
-    }
-
-    /**
-     * Reconstitute the list from a stream (i.e., deserialize it).
-     * @param s the stream
-     */
-    private void readObject(java.io.ObjectInputStream s)
-        throws java.io.IOException, ClassNotFoundException {
-
-        // Read in size, and any hidden stuff
-        s.defaultReadObject();
-
-        // bind to new lock
-        resetLock();
-
-        // Read in array length and allocate array
-        int len = s.readInt();
-        Object[] elements = new Object[len];
-
-        // Read in all elements in the proper order.
-        for (int i = 0; i < len; i++)
-            elements[i] = s.readObject();
-        setArray(elements);
+    static final boolean containsAll(Collection c, Object[] data, int start,
+                                     int size) {
+        if (size == 0) {
+            return false;
+        }
+        Iterator it = c.iterator();
+        while (it.hasNext()) {
+            Object next = it.next();
+            if (indexOf(next, data, start, size) < 0) {
+                return false;
+            }
+        }
+        return true;
     }
 
     /**
-     * Returns a string representation of this list.  The string
-     * representation consists of the string representations of the list's
-     * elements in the order they are returned by its iterator, enclosed in
-     * square brackets (<tt>"[]"</tt>).  Adjacent elements are separated by
-     * the characters <tt>", "</tt> (comma and space).  Elements are
-     * converted to strings as by {@link String#valueOf(Object)}.
+     * Returns the index in the specified range of the data array
+     * of the last occurrence of the specified element
      *
-     * @return a string representation of this list
+     * @param o     element to search
+     * @param data  array where to search
+     * @param start start index
+     * @param size  size of the range
+     * @return
      */
-    public String toString() {
-        return Arrays.toString(getArray());
+    static final int lastIndexOf(Object o, Object[] data, int start, int size) {
+        if (size == 0) {
+            return -1;
+        }
+        if (o != null) {
+            for (int i = start + size - 1; i > start - 1; i--) {
+                if (o.equals(data[i])) {
+                    return i;
+                }
+            }
+        } else {
+            for (int i = start + size - 1; i > start - 1; i--) {
+                if (data[i] == null) {
+                    return i;
+                }
+            }
+        }
+        return -1;
     }
 
     /**
-     * Compares the specified object with this list for equality.
-     * Returns {@code true} if the specified object is the same object
-     * as this object, or if it is also a {@link List} and the sequence
-     * of elements returned by an {@linkplain List#iterator() iterator}
-     * over the specified list is the same as the sequence returned by
-     * an iterator over this list.  The two sequences are considered to
-     * be the same if they have the same length and corresponding
-     * elements at the same position in the sequence are <em>equal</em>.
-     * Two elements {@code e1} and {@code e2} are considered
-     * <em>equal</em> if {@code (e1==null ? e2==null : e1.equals(e2))}.
+     * Returns the index in the specified range of the data array
+     * of the first occurrence of the specified element
      *
-     * @param o the object to be compared for equality with this list
-     * @return {@code true} if the specified object is equal to this list
+     * @param o     element to search
+     * @param data  array where to search
+     * @param start start index
+     * @param size  end index
+     * @return
      */
-    public boolean equals(Object o) {
-        if (o == this)
-            return true;
-        if (!(o instanceof List))
-            return false;
-
-        List<?> list = (List<?>)(o);
-        Iterator<?> it = list.iterator();
-        Object[] elements = getArray();
-        int len = elements.length;
-        for (int i = 0; i < len; ++i)
-            if (!it.hasNext() || !eq(elements[i], it.next()))
-                return false;
-        if (it.hasNext())
-            return false;
-        return true;
+    static final int indexOf(Object o, Object[] data, int start, int size) {
+        if (size == 0) {
+            return -1;
+        }
+        if (o == null) {
+            for (int i = start; i < start + size; i++) {
+                if (data[i] == null) {
+                    return i;
+                }
+            }
+        } else {
+            for (int i = start; i < start + size; i++) {
+                if (o.equals(data[i])) {
+                    return i;
+                }
+            }
+        }
+        return -1;
     }
 
     /**
-     * Returns the hash code value for this list.
-     *
-     * <p>This implementation uses the definition in {@link List#hashCode}.
+     * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
+     * is out of the list bounds.
      *
-     * @return the hash code value for this list
+     * @param index element index to check.
      */
-    public int hashCode() {
-        int hashCode = 1;
-        Object[] elements = getArray();
-        int len = elements.length;
-        for (int i = 0; i < len; ++i) {
-            Object obj = elements[i];
-            hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
+    static final void checkIndexInclusive(int index, int size) {
+        if (index < 0 || index > size) {
+            throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
         }
-        return hashCode;
     }
 
     /**
-     * Returns an iterator over the elements in this list in proper sequence.
+     * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
+     * is out of the list bounds. Excluding the last element.
      *
-     * <p>The returned iterator provides a snapshot of the state of the list
-     * when the iterator was constructed. No synchronization is needed while
-     * traversing the iterator. The iterator does <em>NOT</em> support the
-     * <tt>remove</tt> method.
-     *
-     * @return an iterator over the elements in this list in proper sequence
+     * @param index element index to check.
      */
-    public Iterator<E> iterator() {
-        return new COWIterator<E>(getArray(), 0);
+    static final void checkIndexExlusive(int index, int size) {
+        if (index < 0 || index >= size) {
+            throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
+        }
     }
 
     /**
-     * {@inheritDoc}
+     * gets the internal data array
      *
-     * <p>The returned iterator provides a snapshot of the state of the list
-     * when the iterator was constructed. No synchronization is needed while
-     * traversing the iterator. The iterator does <em>NOT</em> support the
-     * <tt>remove</tt>, <tt>set</tt> or <tt>add</tt> methods.
+     * @return the data array
      */
-    public ListIterator<E> listIterator() {
-        return new COWIterator<E>(getArray(), 0);
+    final E[] getArray() {
+        return arr;
     }
 
     /**
-     * {@inheritDoc}
-     *
-     * <p>The returned iterator provides a snapshot of the state of the list
-     * when the iterator was constructed. No synchronization is needed while
-     * traversing the iterator. The iterator does <em>NOT</em> support the
-     * <tt>remove</tt>, <tt>set</tt> or <tt>add</tt> methods.
-     *
-     * @throws IndexOutOfBoundsException {@inheritDoc}
+     * list iterator implementation,
+     * when created gets snapshot of the list,
+     * so never throws ConcurrentModificationException
      */
-    public ListIterator<E> listIterator(final int index) {
-        Object[] elements = getArray();
-        int len = elements.length;
-        if (index<0 || index>len)
-            throw new IndexOutOfBoundsException("Index: "+index);
+    private static class ListIteratorImpl implements ListIterator {
+        private final Object[] arr;
 
-        return new COWIterator<E>(elements, index);
-    }
+        private int current;
 
-    private static class COWIterator<E> implements ListIterator<E> {
-        /** Snapshot of the array **/
-        private final Object[] snapshot;
-        /** Index of element to be returned by subsequent call to next.  */
-        private int cursor;
+        private final int size;
 
-        private COWIterator(Object[] elements, int initialCursor) {
-            cursor = initialCursor;
-            snapshot = elements;
+        final int size() {
+            return size;
+        }
+
+        public ListIteratorImpl(Object[] data, int current) {
+            this.current = current;
+            arr = data;
+            size = data.length;
+        }
+
+        public void add(Object o) {
+            throw new UnsupportedOperationException("Unsupported operation add");
         }
 
         public boolean hasNext() {
-            return cursor < snapshot.length;
+            if (current < size) {
+                return true;
+            }
+            return false;
         }
 
         public boolean hasPrevious() {
-            return cursor > 0;
+            return current > 0;
         }
 
-        @SuppressWarnings("unchecked")
-        public E next() {
-            if (! hasNext())
-                throw new NoSuchElementException();
-            return (E) snapshot[cursor++];
+        public Object next() {
+            if (hasNext()) {
+                return arr[current++];
+            }
+            throw new NoSuchElementException("pos is " + current + ", size is " + size);
         }
 
-        @SuppressWarnings("unchecked")
-        public E previous() {
-            if (! hasPrevious())
-                throw new NoSuchElementException();
-            return (E) snapshot[--cursor];
+        public int nextIndex() {
+            return current;
         }
 
-        public int nextIndex() {
-            return cursor;
+        public Object previous() {
+            if (hasPrevious()) {
+                return arr[--current];
+            }
+            throw new NoSuchElementException("pos is " + (current-1) + ", size is " + size);
         }
 
         public int previousIndex() {
-            return cursor-1;
+            return current - 1;
         }
 
-        /**
-         * Not supported. Always throws UnsupportedOperationException.
-         * @throws UnsupportedOperationException always; <tt>remove</tt>
-         *         is not supported by this iterator.
-         */
         public void remove() {
-            throw new UnsupportedOperationException();
+            throw new UnsupportedOperationException("Unsupported operation remove");
         }
 
-        /**
-         * Not supported. Always throws UnsupportedOperationException.
-         * @throws UnsupportedOperationException always; <tt>set</tt>
-         *         is not supported by this iterator.
-         */
-        public void set(E e) {
-            throw new UnsupportedOperationException();
+        public void set(Object o) {
+            throw new UnsupportedOperationException("Unsupported operation set");
         }
 
-        /**
-         * Not supported. Always throws UnsupportedOperationException.
-         * @throws UnsupportedOperationException always; <tt>add</tt>
-         *         is not supported by this iterator.
-         */
-        public void add(E e) {
-            throw new UnsupportedOperationException();
-        }
     }
 
     /**
-     * Returns a view of the portion of this list between
-     * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
-     * The returned list is backed by this list, so changes in the
-     * returned list are reflected in this list.
-     *
-     * <p>The semantics of the list returned by this method become
-     * undefined if the backing list (i.e., this list) is modified in
-     * any way other than via the returned list.
-     *
-     * @param fromIndex low endpoint (inclusive) of the subList
-     * @param toIndex high endpoint (exclusive) of the subList
-     * @return a view of the specified range within this list
-     * @throws IndexOutOfBoundsException {@inheritDoc}
+     * Keeps a state of sublist implementation,
+     * size and array declared as final,
+     * so we'll never get the unconsistent state
      */
-    public List<E> subList(int fromIndex, int toIndex) {
-        final ReentrantLock lock = this.lock;
-        lock.lock();
-        try {
-            Object[] elements = getArray();
-            int len = elements.length;
-            if (fromIndex < 0 || toIndex > len || fromIndex > toIndex)
-                throw new IndexOutOfBoundsException();
-            return new COWSubList<E>(this, fromIndex, toIndex);
-        } finally {
-            lock.unlock();
+    static final class SubListReadData {
+        final int size;
+
+        final Object[] data;
+
+        SubListReadData(int size, Object[] data) {
+            this.size = size;
+            this.data = data;
         }
     }
 
     /**
-     * Sublist for CopyOnWriteArrayList.
-     * This class extends AbstractList merely for convenience, to
-     * avoid having to define addAll, etc. This doesn't hurt, but
-     * is wasteful.  This class does not need or use modCount
-     * mechanics in AbstractList, but does need to check for
-     * concurrent modification using similar mechanics.  On each
-     * operation, the array that we expect the backing list to use
-     * is checked and updated.  Since we do this for all of the
-     * base operations invoked by those defined in AbstractList,
-     * all is well.  While inefficient, this is not worth
-     * improving.  The kinds of list operations inherited from
-     * AbstractList are already so slow on COW sublists that
-     * adding a bit more space/time doesn't seem even noticeable.
+     * Represents a list returned by <code>sublist()</code>.
      */
-    private static class COWSubList<E>
-        extends AbstractList<E>
-        implements RandomAccess
-    {
-        private final CopyOnWriteArrayList<E> l;
-        private final int offset;
-        private int size;
-        private Object[] expectedArray;
-
-        // only call this holding l's lock
-        COWSubList(CopyOnWriteArrayList<E> list,
-                   int fromIndex, int toIndex) {
-            l = list;
-            expectedArray = l.getArray();
-            offset = fromIndex;
-            size = toIndex - fromIndex;
-        }
-
-        // only call this holding l's lock
-        private void checkForComodification() {
-            if (l.getArray() != expectedArray)
+    static class SubList implements List {
+        private final CopyOnWriteArrayList list;
+
+        private volatile SubListReadData read;
+
+        private final int start;
+
+        /**
+         * Sublist constructor.
+         *
+         * @param list    backing list.
+         * @param fromIdx startingIndex, inclusive
+         * @param toIdx   endIndex, exclusive
+         */
+        public SubList(CopyOnWriteArrayList list, int fromIdx, int toIdx) {
+            this.list = list;
+            Object[] data = list.getData();
+            int size = toIdx - fromIdx;
+            checkIndexExlusive(fromIdx, data.length);
+            checkIndexInclusive(toIdx, data.length);
+            read = new SubListReadData(size, list.getData());
+            start = fromIdx;
+        }
+
+        /**
+         * throws ConcurrentModificationException when the list
+         * is structurally modified in the other way other than via this subList
+         * <p/>
+         * Should be called under lock!
+         */
+        private void checkModifications() {
+            if (read.data != list.getData()) {
                 throw new ConcurrentModificationException();
+            }
         }
 
-        // only call this holding l's lock
-        private void rangeCheck(int index) {
-            if (index<0 || index>=size)
-                throw new IndexOutOfBoundsException("Index: "+index+
-                                                    ",Size: "+size);
+        /**
+         * @see java.util.List#listIterator(int)
+         */
+        public ListIterator listIterator(int startIdx) {
+            return new SubListIterator(startIdx, read);
         }
 
-        public E set(int index, E element) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        /**
+         * @see java.util.List#set(int, java.lang.Object)
+         */
+        public Object set(int index, Object obj) {
+            list.lock.lock();
             try {
-                rangeCheck(index);
-                checkForComodification();
-                E x = l.set(index+offset, element);
-                expectedArray = l.getArray();
-                return x;
+                checkIndexExlusive(index, read.size);
+                checkModifications();
+                Object result = list.set(index + start, obj);
+                read = new SubListReadData(read.size, list.getData());
+                return result;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public E get(int index) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        /**
+         * @see java.util.List#get(int)
+         */
+        public Object get(int index) {
+            SubListReadData data = read;
+            if (data.data != list.getData()) {
+                list.lock.lock();
+                try {
+                    data = read;
+                    if (data.data != list.getData()) {
+                        throw new ConcurrentModificationException();
+                    }
+                } finally {
+                    list.lock.unlock();
+                }
+            }
+            checkIndexExlusive(index, data.size);
+            return data.data[index + start];
+        }
+
+        /**
+         * @see java.util.Collection#size()
+         */
+        public int size() {
+            return read.size;
+        }
+
+        /**
+         * @see java.util.List#remove(int)
+         */
+        public Object remove(int index) {
+            list.lock.lock();
             try {
-                rangeCheck(index);
-                checkForComodification();
-                return l.get(index+offset);
+                checkIndexExlusive(index, read.size);
+                checkModifications();
+                Object obj = list.remove(index + start);
+                read = new SubListReadData(read.size - 1, list.getData());
+                return obj;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public int size() {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        /**
+         * @see java.util.List#add(int, java.lang.Object)
+         */
+        public void add(int index, Object object) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                return size;
+                checkIndexInclusive(index, read.size);
+                checkModifications();
+                list.add(index + start, object);
+                read = new SubListReadData(read.size + 1, list.getData());
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public void add(int index, E element) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public boolean add(Object o) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                if (index<0 || index>size)
-                    throw new IndexOutOfBoundsException();
-                l.add(index+offset, element);
-                expectedArray = l.getArray();
-                size++;
+                checkModifications();
+                list.add(start + read.size, o);
+                read = new SubListReadData(read.size + 1, list.getData());
+                return true;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public void clear() {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public boolean addAll(Collection c) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                l.removeRange(offset, offset+size);
-                expectedArray = l.getArray();
-                size = 0;
+                checkModifications();
+                int d = list.size();
+                list.addAll(start + read.size, c);
+                read = new SubListReadData(read.size + (list.size() - d), list
+                        .getData());
+                return true;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public E remove(int index) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public void clear() {
+            list.lock.lock();
             try {
-                rangeCheck(index);
-                checkForComodification();
-                E result = l.remove(index+offset);
-                expectedArray = l.getArray();
-                size--;
-                return result;
+                checkModifications();
+                list.removeRange(start, read.size);
+                read = new SubListReadData(0, list.getData());
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public boolean remove(Object o) {
-            int index = indexOf(o);
-            if (index == -1)
-                return false;
-            remove(index);
-            return true;
+        public boolean contains(Object o) {
+            return indexOf(o) != -1;
+        }
+
+        public boolean containsAll(Collection c) {
+            SubListReadData b = read;
+            return CopyOnWriteArrayList.containsAll(c, b.data, start, b.size);
         }
 
-        public Iterator<E> iterator() {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public int indexOf(Object o) {
+            SubListReadData b = read;
+            int ind = CopyOnWriteArrayList.indexOf(o, b.data, start, b.size)
+                    - start;
+            return ind < 0 ? -1 : ind;
+        }
+
+        public boolean isEmpty() {
+            return read.size == 0;
+        }
+
+        public Iterator iterator() {
+            return new SubListIterator(0, read);
+        }
+
+        public int lastIndexOf(Object o) {
+            SubListReadData b = read;
+            int ind = CopyOnWriteArrayList
+                    .lastIndexOf(o, b.data, start, b.size)
+                    - start;
+            return ind < 0 ? -1 : ind;
+        }
+
+        public ListIterator listIterator() {
+            return new SubListIterator(0, read);
+        }
+
+        public boolean remove(Object o) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                return new COWSubListIterator<E>(l, 0, offset, size);
+                checkModifications();
+                int i = indexOf(o);
+                if (i == -1) {
+                    return false;
+                }
+                boolean result = list.remove(i + start) != null;
+                if (result) {
+                    read = new SubListReadData(read.size - 1, list.getData());
+                }
+                return result;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-        public ListIterator<E> listIterator(final int index) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public boolean removeAll(Collection c) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                if (index<0 || index>size)
-                    throw new IndexOutOfBoundsException("Index: "+index+
-                                                        ", Size: "+size);
-                return new COWSubListIterator<E>(l, index, offset, size);
+                checkModifications();
+                int removed = list.removeAll(c, start, read.size);
+                if (removed > 0) {
+                    read = new SubListReadData(read.size - removed, list
+                            .getData());
+                    return true;
+                }
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
+            return false;
         }
 
-        public List<E> subList(int fromIndex, int toIndex) {
-            final ReentrantLock lock = l.lock;
-            lock.lock();
+        public boolean retainAll(Collection c) {
+            list.lock.lock();
             try {
-                checkForComodification();
-                if (fromIndex<0 || toIndex>size)
-                    throw new IndexOutOfBoundsException();
-                return new COWSubList<E>(l, fromIndex + offset,
-                                         toIndex + offset);
+                checkModifications();
+                int removed = list.retainAll(c, start, read.size);
+                if (removed > 0) {
+                    read = new SubListReadData(read.size - removed, list
+                            .getData());
+                    return true;
+                }
+                return false;
             } finally {
-                lock.unlock();
+                list.lock.unlock();
             }
         }
 
-    }
-
-
-    private static class COWSubListIterator<E> implements ListIterator<E> {
-        private final ListIterator<E> i;
-        private final int index;
-        private final int offset;
-        private final int size;
-
-        COWSubListIterator(List<E> l, int index, int offset,
-                           int size) {
-            this.index = index;
-            this.offset = offset;
-            this.size = size;
-            i = l.listIterator(index+offset);
+        public List subList(int fromIndex, int toIndex) {
+            return new SubList(list, start + fromIndex, start + toIndex);
         }
 
-        public boolean hasNext() {
-            return nextIndex() < size;
+        public Object[] toArray() {
+            SubListReadData r = read;
+            return CopyOnWriteArrayList.toArray(r.data, start, r.size);
         }
 
-        public E next() {
-            if (hasNext())
-                return i.next();
-            else
-                throw new NoSuchElementException();
+        public Object[] toArray(Object[] a) {
+            SubListReadData r = read;
+            return CopyOnWriteArrayList.toArray(a, r.data, start, r.size);
         }
 
-        public boolean hasPrevious() {
-            return previousIndex() >= 0;
+        /**
+         * @see java.util.List#addAll(int, java.util.Collection)
+         */
+        public boolean addAll(int index, Collection collection) {
+            list.lock.lock();
+            try {
+                checkIndexInclusive(index, read.size);
+                checkModifications();
+                int d = list.size();
+                boolean rt = list.addAll(index + start, collection);
+                read = new SubListReadData(read.size + list.size() - d, list
+                        .getData());
+                return rt;
+            } finally {
+                list.lock.unlock();
+            }
         }
 
-        public E previous() {
-            if (hasPrevious())
-                return i.previous();
-            else
-                throw new NoSuchElementException();
-        }
+        /**
+         * Implementation of <code>ListIterator</code> for the
+         * <code>SubList</code>
+         * gets a snapshot of the sublist,
+         * never throws ConcurrentModificationException
+         */
+        private class SubListIterator extends ListIteratorImpl {
+            private final SubListReadData dataR;
+
+            /**
+             * Constructs an iterator starting with the given index
+             *
+             * @param index index of the first element to iterate.
+             */
+            private SubListIterator(int index, SubListReadData d) {
+                super(d.data, index + start);
+                this.dataR = d;
+            }
 
-        public int nextIndex() {
-            return i.nextIndex() - offset;
-        }
+            /**
+             * @see java.util.ListIterator#nextIndex()
+             */
+            public int nextIndex() {
+                return super.nextIndex() - start;
+            }
 
-        public int previousIndex() {
-            return i.previousIndex() - offset;
-        }
+            /**
+             * @see java.util.ListIterator#previousIndex()
+             */
+            public int previousIndex() {
+                return super.previousIndex() - start;
+            }
 
-        public void remove() {
-            throw new UnsupportedOperationException();
-        }
+            /**
+             * @see java.util.Iterator#hasNext()
+             */
+            public boolean hasNext() {
+                return nextIndex() < dataR.size;
+            }
 
-        public void set(E e) {
-            throw new UnsupportedOperationException();
+            /**
+             * @see java.util.ListIterator#hasPrevious()
+             */
+            public boolean hasPrevious() {
+                return previousIndex() > -1;
+            }
         }
 
-        public void add(E e) {
-            throw new UnsupportedOperationException();
-        }
     }
 
-    // Support for resetting lock while deserializing
-    private static final Unsafe unsafe = Unsafe.getUnsafe();
-    private static final long lockOffset;
-    static {
-        try {
-            lockOffset = unsafe.objectFieldOffset
-                (CopyOnWriteArrayList.class.getDeclaredField("lock"));
-            } catch (Exception ex) { throw new Error(ex); }
+    //serialization support
+    /**
+     * Writes the object state to the ObjectOutputStream.
+     *
+     * @param oos ObjectOutputStream to write object to.
+     * @throws IOException if an I/O error occur.
+     */
+    private void writeObject(ObjectOutputStream oos) throws IOException {
+        E[] back = getData();
+        int size = back.length;
+        oos.defaultWriteObject();
+        oos.writeInt(size);
+        for (int i = 0; i < size; i++) {
+            oos.writeObject(back[i]);
+        }
     }
-    private void resetLock() {
-        unsafe.putObjectVolatile(this, lockOffset, new ReentrantLock());
+
+    /**
+     * Reads the object state from the ObjectOutputStream.
+     *
+     * @param ois ObjectInputStream to read object from.
+     * @throws IOException if an I/O error occur.
+     */
+    private void readObject(ObjectInputStream ois) throws IOException,
+            ClassNotFoundException {
+        ois.defaultReadObject();
+        int length = ois.readInt();
+        if (length == 0) {
+            setData(newElementArray(0));
+        } else {
+            E[] back = newElementArray(length);
+            for (int i = 0; i < back.length; i++) {
+                back[i] = (E) ois.readObject();
+            }
+            setData(back);
+        }
     }
+
 }
index 641e856..653e4d0 100644 (file)
@@ -109,12 +109,27 @@ public class Zygote {
      * dimension having a length of 3 and representing
      * (resource, rlim_cur, rlim_max). These are set via the posix
      * setrlimit(2) call.
+     * @param permittedCapabilities argument for setcap()
+     * @param effectiveCapabilities argument for setcap()
      *
      * @return 0 if this is the child, pid of the child
      * if this is the parent, or -1 on error.
+     *
+     * @hide
+     */
+    native public static int forkSystemServer(int uid, int gid,
+            int[] gids, int debugFlags, int[][] rlimits,
+            long permittedCapabilities, long effectiveCapabilities);
+
+    /*
+     * For bug 3176774, we needed to update forkSystemServer() after
+     * the API was locked down.  To avoid going out of sync with the
+     * API description file, we provide a dummy function here.
      */
-    native public static int forkSystemServer(int uid, int gid, 
-            int[] gids, int debugFlags, int[][] rlimits);
+    public static int forkSystemServer(int uid, int gid,
+            int[] gids, int debugFlags, int[][] rlimits) {
+        throw new UnsupportedOperationException();
+    }
 
     /**
      * Special method to start the system server process.
index a24f457..7183bad 100644 (file)
@@ -1999,10 +1999,13 @@ public class ThreadTest extends junit.framework.TestCase {
 
         while (!sem.hasQueuedThreads()){}
         
+        long start = System.currentTimeMillis();
+        while(start + 1000 > System.currentTimeMillis()) {}
         assertEquals(Thread.State.WAITING, th.getState());
+
         synchronized (lock) {
             sem.release();
-            long start = System.currentTimeMillis();
+            start = System.currentTimeMillis();
             while(start + 1000 > System.currentTimeMillis()) {}
             assertEquals(Thread.State.BLOCKED, th.getState());
         }
index 276dfd7..7cf12b5 100644 (file)
@@ -40,23 +40,14 @@ import java.security.cert.Certificate;
 import org.apache.harmony.security.tests.support.TestCertUtils;
 
 import junit.framework.TestCase;
+
 @TestTargetClass(CodeSource.class)
 /**
  * Unit test for CodeSource.
- * 
+ *
  */
 
 public class CodeSourceTest extends TestCase {
-    /**
-     * 
-     * Entry point for standalone runs.
-     *
-     * @param args command line arguments
-     */
-    public static void main(String[] args) throws Exception {
-        junit.textui.TestRunner.run(CodeSourceTest.class);
-    }
-
     private java.security.cert.Certificate[] chain = null;
 
     /* Below are various URLs used during the testing */
@@ -83,7 +74,7 @@ public class CodeSourceTest extends TestCase {
     private static URL urlFileDirStar;
 
     private static URL urlRef1, urlRef2;
-    
+
     private boolean init = false;
 
     private void init() {
@@ -92,28 +83,28 @@ public class CodeSourceTest extends TestCase {
                 String siteName = "www.intel.com";
                 InetAddress addr = InetAddress.getByName(siteName);
                 String siteIP = addr.getHostAddress();
-    
+
                 urlSite = new URL("http://"+siteName+"");
                 urlDir = new URL("http://"+siteName+"/drl_test");
                 urlDirOtherSite = new URL("http://www.any-other-site-which-is-not-siteName.com/drl_test");
-    
+
                 urlDir_port80 = new URL("http://"+siteName+":80/drl_test");
                 urlDir_port81 = new URL("http://"+siteName+":81/drl_test");
                 urlDirWithSlash = new URL(urlDir + "/");
-    
+
                 //urlDirFtp = new URL("ftp://www.intel.com/drl_test");
                 urlDir_FileProtocol = new URL("file://"+siteName+"/drl_test");
-    
+
                 urlDirIP = new URL("http://"+siteIP+"/drl_test");
-    
+
                 urlFile = new URL("http://"+siteName+"/drl_test/empty.jar");
                 urlFileWithAdditionalDirs = new URL(
                         "http://"+siteName+"/drl_test/what/ever/here/empty.jar");
-    
+
                 urlFileDirMinus = new URL("http://"+siteName+"/drl_test/-");
                 urlFileDirStar = new URL("http://"+siteName+"/drl_test/*");
                 urlFileDirOtherDir = new URL("http://"+siteName+"/_test_drl_/*");
-    
+
                 urlRef1 = new URL("http://"+siteName+"/drl_test/index.html#ref1");
                 urlRef2 = new URL("http://"+siteName+"/drl_test/index.html#ref2");
             } catch (MalformedURLException ex) {
@@ -134,7 +125,7 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Tests hashCode().<br>
-     * javadoc says nothing, so test DRL-specific implementation. 
+     * javadoc says nothing, so test DRL-specific implementation.
      */
     @TestTargetNew(
         level = TestLevel.COMPLETE,
@@ -143,7 +134,7 @@ public class CodeSourceTest extends TestCase {
         args = {}
     )
     public void testHashCode() {
-        // when nothing is specified, then hashCode obviously must be 0. 
+        // when nothing is specified, then hashCode obviously must be 0.
         assertTrue(new CodeSource(null, (Certificate[]) null).hashCode() == 0);
         // only URL.hashCode is taken into account...
         assertTrue(new CodeSource(urlSite, (Certificate[]) null).hashCode() == urlSite
@@ -217,7 +208,7 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Test for equals(Object)<br>
-     * The signer certificate chain must contain the same set of certificates, but 
+     * The signer certificate chain must contain the same set of certificates, but
      * the order of the certificates is not taken into account.
      */
     @TestTargetNew(
@@ -238,7 +229,7 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Test for equals(Object)<br>
-     * Checks that both 'null' and not-null URLs are taken into account - properly. 
+     * Checks that both 'null' and not-null URLs are taken into account - properly.
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -277,7 +268,7 @@ public class CodeSourceTest extends TestCase {
     }
 
     /**
-     * Tests whether the getCertificates() returns certificates obtained from 
+     * Tests whether the getCertificates() returns certificates obtained from
      * the signers.
      */
     @TestTargetNew(
@@ -295,19 +286,19 @@ public class CodeSourceTest extends TestCase {
         CodeSigner[] signers = { new CodeSigner(cpath, null) };
         CodeSource cs = new CodeSource(null, signers);
         Certificate[] got = cs.getCertificates();
-        // The set of certificates must be exactly the same, 
+        // The set of certificates must be exactly the same,
         // but the order is not specified
         assertTrue(presented(certs, got));
         assertTrue(presented(got, certs));
     }
 
     /**
-     * Checks whether two arrays of certificates represent the same same set of 
+     * Checks whether two arrays of certificates represent the same same set of
      * certificates - in the same order.
-     * @param one first array 
+     * @param one first array
      * @param two second array
-     * @return <code>true</code> if both arrays represent the same set of 
-     * certificates, 
+     * @return <code>true</code> if both arrays represent the same set of
+     * certificates,
      * <code>false</code> otherwise.
      */
     private static boolean checkEqual(java.security.cert.Certificate[] one,
@@ -342,10 +333,10 @@ public class CodeSourceTest extends TestCase {
     /**
      * Performs a test whether the <code>what</code> certificates are all
      * presented in <code>where</code> certificates.
-     * 
+     *
      * @param what - first array of Certificates
      * @param where  - second array of Certificates
-     * @return <code>true</code> if each and every certificate from 'what' 
+     * @return <code>true</code> if each and every certificate from 'what'
      * (including null) is presented in 'where' <code>false</code> otherwise
      */
     private static boolean presented(Certificate[] what, Certificate[] where) {
@@ -413,7 +404,7 @@ public class CodeSourceTest extends TestCase {
             assertTrue(found);
         }
     }
-    
+
     /**
      * Tests CodeSource.getCodeSigners() for null.
      */
@@ -424,7 +415,7 @@ public class CodeSourceTest extends TestCase {
         args = {}
     )
     public void testGetCoderSignersNull() throws Exception{
-        assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners()); //$NON-NLS-1$
+        assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners());
     }
 
     /**
@@ -453,7 +444,7 @@ public class CodeSourceTest extends TestCase {
         args = {}
     )
     public void testToString() {
-        // Javadoc keeps silence about String's format, 
+        // Javadoc keeps silence about String's format,
         // just make sure it can be invoked.
         new CodeSource(urlSite, chain).toString();
         new CodeSource(null, chain).toString();
@@ -462,9 +453,9 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Tests whether we are running with the 1.5 features.<br>
-     * The test is preformed by looking for (via reflection) the CodeSource's 
+     * The test is preformed by looking for (via reflection) the CodeSource's
      * constructor  {@link CodeSource#CodeSource(URL, CodeSigner[])}.
-     * @return <code>true</code> if 1.5 feature is presented, <code>false</code> 
+     * @return <code>true</code> if 1.5 feature is presented, <code>false</code>
      * otherwise.
      */
     private static boolean has_15_features() {
@@ -473,7 +464,7 @@ public class CodeSourceTest extends TestCase {
         try {
             klass.getConstructor(ctorArgs);
         } catch (NoSuchMethodException ex) {
-            // NoSuchMethod == Not RI.v1.5 and not DRL 
+            // NoSuchMethod == Not RI.v1.5 and not DRL
             return false;
         }
         return true;
@@ -512,9 +503,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thizCS.implies(thatCS));
     }
 
-    /**
-     * If this object's location equals codesource's location, then return true.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -530,10 +518,6 @@ public class CodeSourceTest extends TestCase {
 
     }
 
-    /**
-     * This object's protocol (getLocation().getProtocol()) must be equal to
-     * codesource's protocol.
-     */
     /*
      * FIXME
      * commented out for temporary, as there is no FTP:// protocol supported yet.
@@ -559,11 +543,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thatCS.implies(thizCS));
     }
 
-    /**
-     * If this object's host (getLocation().getHost()) is not null, then the
-     * SocketPermission constructed with this object's host must imply the
-     * SocketPermission constructed with codesource's host.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -577,7 +556,7 @@ public class CodeSourceTest extends TestCase {
         assertTrue(thizCS.implies(thatCS));
         assertTrue(thatCS.implies(thizCS));
 
-        // 
+        //
         // Check for another site - force to create SocketPermission
         //
         thatCS = new CodeSource(urlDirOtherSite, (Certificate[]) null);
@@ -595,10 +574,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thatCS.implies(thizCS));
     }
 
-    /**
-     * If this object's port (getLocation().getPort()) is not equal to -1 (that
-     * is, if a port is specified), it must equal codesource's port.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -626,10 +601,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thizCS.implies(thatCS));
     }
 
-    /**
-     * If this object's file (getLocation().getFile()) doesn't equal
-     * codesource's file, then the following checks are made: ...
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -642,10 +613,6 @@ public class CodeSourceTest extends TestCase {
         assertTrue(thizCS.implies(thatCS));
     }
 
-    /**
-     * ... If this object's file ends with "/-", then codesource's file must
-     * start with this object's file (exclusive the trailing "-").
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -664,11 +631,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thiz.implies(that));
     }
 
-    /**
-     * ... If this object's file ends with a "/*", then codesource's file must
-     * start with this object's file and must not have any further "/"
-     * separators.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -690,10 +652,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thiz.implies(that));
     }
 
-    /**
-     * ... If this object's file doesn't end with a "/", then codesource's file
-     * must match this object's file with a '/' appended.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -708,10 +666,6 @@ public class CodeSourceTest extends TestCase {
         assertFalse(thatCS.implies(thizCS));
     }
 
-    /**
-     * If this object's reference (getLocation().getRef()) is not null, it must
-     * equal codesource's reference.
-     */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
         notes = "",
@@ -754,7 +708,7 @@ public class CodeSourceTest extends TestCase {
 
         //
         that = new CodeSource(urlSite, (Certificate[]) null);
-        // 'thiz' has set of certs, while 'that' has no certs. URL-s are the 
+        // 'thiz' has set of certs, while 'that' has no certs. URL-s are the
         // same.
         assertFalse(thiz.implies(that));
         assertTrue(that.implies(thiz));
@@ -762,8 +716,8 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Testing with special URLs like 'localhost', 'file://' scheme ...
-     * These special URLs have a special processing in implies(), 
-     * so they need to be covered and performance need to be checked 
+     * These special URLs have a special processing in implies(),
+     * so they need to be covered and performance need to be checked
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -783,8 +737,8 @@ public class CodeSourceTest extends TestCase {
 
     /**
      * Testing with special URLs like 'localhost', 'file://' scheme ...
-     * These special URLs have a special processing in implies(), 
-     * so they need to be covered and performance need to be checked 
+     * These special URLs have a special processing in implies(),
+     * so they need to be covered and performance need to be checked
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
index 734e11d..a4abf14 100644 (file)
-// Copyright 2009 Google Inc. All Rights Reserved.
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 package org.bouncycastle.jce.provider;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import javax.security.auth.x500.X500Principal;
 import junit.framework.TestCase;
-import org.apache.harmony.security.provider.cert.X509CertImpl;
-import org.apache.harmony.security.provider.cert.X509CertPathImpl;
-import org.bouncycastle.asn1.x509.X509CertificateStructure;
-import org.bouncycastle.asn1.ASN1Sequence;
-import org.bouncycastle.asn1.ASN1InputStream;
 
 import java.io.IOException;
-import java.util.Arrays;
-import java.util.Set;
-import java.util.HashSet;
-import java.security.cert.CertificateException;
-import java.security.cert.TrustAnchor;
-import java.security.cert.CertPathValidatorException;
-import java.security.KeyStoreException;
-import java.security.InvalidAlgorithmParameterException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.fail;
+import junit.framework.AssertionFailedError;
 
 /**
  * Verify the behavior of PKIXCertPathValidatorSpi.
  */
 public class PKIXCertPathValidatorSpiTest extends TestCase {
 
+  public void testSerialization() {
+        String expected = "aced0005737200266a617661782e73656375726974792e617574682e7"
+                + "83530302e583530305072696e636970616cf90dff3c88b877c703000078707572"
+                + "00025b42acf317f8060854e002000078700000006a30683117301506035504031"
+                + "30e7777772e676f6f676c652e636f6d31133011060355040a130a476f6f676c65"
+                + "20496e63311630140603550407130d4d6f756e7461696e2056696577311330110"
+                + "603550408130a43616c69666f726e6961310b300906035504061302555378";
+        X500Principal actual = new X500Principal("C=US, "
+                                                 + "ST=California, "
+                                                 + "L=Mountain View, "
+                                                 + "O=Google Inc, "
+                                                 + "CN=www.google.com");
+        new SerializableTester<X500Principal>(actual, expected).test();
+    }
+
     /**
-     * A chain of 3 ASN1-encoded certificates for https://service.sprint.com.
-     * The certificate subjects are "service.sprint.com", "Entrust Certification
-     * Authority - L1B", and "Entrust.net Certification Authority (2048)". The
-     * last certificate uses UTF8 encoding for its X509 name.
+     * ASN1-encoded trusted certificate #946059622 for
+     * Entrust.net. This certificate uses the T61String (aka
+     * TeletexString or TELETEXSTRING) encoding for one
+     * organizationalUnitNames:
+     *
+     * "www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)"
      */
-    private final byte[][] serviceSprintComCertChain = new byte[][] {
-            new byte[] { 48, -126, 6, 89, 48, -126, 5, 65, -96, 3, 2, 1, 2, 2, 4, 72, 13, 115, -81, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, 30, 23, 13, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, 23, 13, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 120, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 15, 48, 13, 6, 3, 85, 4, 8, 19, 6, 75, 65, 78, 83, 65, 83, 49, 22, 48, 20, 6, 3, 85, 4, 7, 19, 13, 79, 118, 101, 114, 108, 97, 110, 100, 32, 80, 97, 114, 107, 49, 15, 48, 13, 6, 3, 85, 4, 10, 19, 6, 83, 112, 114, 105, 110, 116, 49, 18, 48, 16, 6, 3, 85, 4, 11, 19, 9, 100, 97, 115, 110, 109, 112, 48, 52, 98, 49, 27, 48, 25, 6, 3, 85, 4, 3, 19, 18, 115, 101, 114, 118, 105, 99, 101, 46, 115, 112, 114, 105, 110, 116, 46, 99, 111, 109, 48, -127, -97, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -127, -115, 0, 48, -127, -119, 2, -127, -127, 0, -80, 99, 109, 108, 94, -41, -78, 88, 56, -97, 33, -23, 65, -74, -118, 0, 1, 119, 126, 122, -59, -83, -25, -16, -75, -87, 100, 46, 37, -98, 65, -104, 54, -87, 56, -81, 96, -38, -4, -78, 11, 101, -29, 70, -13, -110, -76, -125, -106, -35, 41, 83, 71, 56, 6, 67, -8, 82, -58, -81, -113, 90, 91, 79, 74, -38, 34, 28, 39, -37, -12, 54, 87, 61, 48, 33, -16, 10, 112, -40, -37, -15, 59, -72, 112, 96, 85, 109, 123, -122, 58, 18, 95, 56, -81, 49, 43, -39, 99, 69, -28, -81, -106, -64, 8, -62, 40, -92, 95, -109, -122, 94, 53, -13, -33, 88, -104, 3, -77, -30, -27, 23, 92, -69, 12, -23, -9, 125, 2, 3, 1, 0, 1, -93, -126, 2, -81, 48, -126, 2, -85, 48, 11, 6, 3, 85, 29, 15, 4, 4, 3, 2, 5, -96, 48, 43, 6, 3, 85, 29, 16, 4, 36, 48, 34, -128, 15, 50, 48, 48, 57, 48, 52, 50, 57, 49, 53, 50, 54, 53, 57, 90, -127, 15, 50, 48, 49, 49, 48, 53, 48, 53, 49, 53, 53, 54, 53, 55, 90, 48, 19, 6, 3, 85, 29, 37, 4, 12, 48, 10, 6, 8, 43, 6, 1, 5, 5, 7, 3, 1, 48, 51, 6, 3, 85, 29, 31, 4, 44, 48, 42, 48, 40, -96, 38, -96, 36, -122, 34, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 108, 101, 118, 101, 108, 49, 98, 46, 99, 114, 108, 48, 100, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 88, 48, 86, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 47, 6, 8, 43, 6, 1, 5, 5, 7, 48, 2, -122, 35, 104, 116, 116, 112, 58, 47, 47, 97, 105, 97, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 45, 108, 49, 98, 46, 99, 101, 114, 48, -126, 1, 87, 6, 3, 85, 29, 32, 4, -126, 1, 78, 48, -126, 1, 74, 48, -126, 1, 70, 6, 9, 42, -122, 72, -122, -10, 125, 7, 75, 2, 48, -126, 1, 55, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 48, -126, 1, 11, 6, 8, 43, 6, 1, 5, 5, 7, 2, 2, 48, -127, -2, 26, -127, -5, 84, 104, 101, 32, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 80, 114, 97, 99, 116, 105, 99, 101, 32, 83, 116, 97, 116, 101, 109, 101, 110, 116, 32, 40, 67, 80, 83, 41, 32, 97, 118, 97, 105, 108, 97, 98, 108, 101, 32, 97, 116, 32, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 99, 112, 115, 32, 32, 105, 115, 32, 104, 101, 114, 101, 98, 121, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 105, 110, 116, 111, 32, 121, 111, 117, 114, 32, 117, 115, 101, 32, 111, 114, 32, 114, 101, 108, 105, 97, 110, 99, 101, 32, 111, 110, 32, 116, 104, 105, 115, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 101, 46, 32, 32, 84, 104, 105, 115, 32, 67, 80, 83, 32, 99, 111, 110, 116, 97, 105, 110, 115, 32, 108, 105, 109, 105, 116, 97, 116, 105, 111, 110, 115, 32, 111, 110, 32, 119, 97, 114, 114, 97, 110, 116, 105, 101, 115, 32, 97, 110, 100, 32, 108, 105, 97, 98, 105, 108, 105, 116, 105, 101, 115, 46, 32, 67, 111, 112, 121, 114, 105, 103, 104, 116, 32, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 32, 76, 105, 109, 105, 116, 101, 100, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 68, 101, 26, -23, -69, -107, 32, 89, 18, 28, -123, 32, 74, -116, -33, -48, 70, -52, 68, 77, 48, 9, 6, 3, 85, 29, 19, 4, 2, 48, 0, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 3, 40, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 18, 56, 92, -74, -100, -56, 95, 121, 27, -84, -88, -104, -27, -98, -12, 58, 48, -26, 40, -7, 25, -68, -124, -104, -54, -121, 84, 52, 3, 22, -106, 88, 44, -39, 126, 17, 96, 4, -41, -84, -101, 74, -92, -113, -12, -99, 77, 108, -30, 38, 19, 78, 48, 32, -126, 95, -10, -114, 58, 98, -49, -108, -109, -87, 5, -80, -43, 121, 21, -99, 43, -73, 26, 51, 31, 87, -38, -119, 78, -113, -59, -100, -118, -84, -46, -48, 93, 99, 2, 40, -39, 76, -48, -122, -60, -25, -73, 103, 126, 83, -86, -26, 66, 122, -65, -89, -102, 115, 105, -124, -85, -18, -66, 85, 30, -29, -96, 104, 65, -66, 40, 69, -91, 101, -19, 39, -86, -21, -18, 39, 51, -1, 36, -52, 53, -65, 53, 12, -62, -97, -45, -26, 113, -20, 102, 56, 102, 104, 37, 17, 57, -96, -83, -71, 106, 63, -64, -122, 61, 59, 8, -123, 108, 22, 62, -58, -105, 88, 38, 96, -6, -29, -114, 105, 110, -102, -72, 109, -33, 56, 61, 52, 70, -75, -92, 97, -9, -6, -64, 53, -76, 81, -100, 90, -50, 19, -87, 30, -24, -53, 109, -75, 45, -38, 14, 119, -31, 44, -30, -93, -76, 14, 97, -53, -107, 60, 30, -102, 68, 12, 26, 76, -114, 73, -13, -127, 21, 94, -42, 94, 30, -50, -3, 116, 41, -3, -89, 23, -27, -49, -3, -95, 119, -104, -45, 112, 35, 66, 59, 84, 116, 19, -102, -68, -104, 1 },
-            new byte[] { 48, -126, 5, -111, 48, -126, 4, 121, -96, 3, 2, 1, 2, 2, 4, 56, 99, -59, -82, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 48, 56, 48, 56, 50, 53, 49, 56, 49, 52, 50, 54, 90, 23, 13, 49, 56, 48, 56, 50, 53, 49, 56, 52, 52, 50, 54, 90, 48, -126, 1, 52, 49, 11, 48, 9, 6, 3, 85, 4, 6, 19, 2, 85, 83, 49, 22, 48, 20, 6, 3, 85, 4, 10, 19, 13, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 56, 48, 54, 6, 3, 85, 4, 11, 19, 47, 65, 78, 68, 32, 65, 68, 68, 73, 84, 73, 79, 78, 65, 76, 32, 84, 69, 82, 77, 83, 32, 71, 79, 86, 69, 82, 78, 73, 78, 71, 32, 85, 83, 69, 32, 65, 78, 68, 32, 82, 69, 76, 73, 65, 78, 67, 69, 49, 71, 48, 69, 6, 3, 85, 4, 11, 19, 62, 67, 80, 83, 32, 67, 79, 78, 84, 65, 73, 78, 83, 32, 73, 77, 80, 79, 82, 84, 65, 78, 84, 32, 76, 73, 77, 73, 84, 65, 84, 73, 79, 78, 83, 32, 79, 70, 32, 87, 65, 82, 82, 65, 78, 84, 73, 69, 83, 32, 65, 78, 68, 32, 76, 73, 65, 66, 73, 76, 73, 84, 89, 49, 57, 48, 55, 6, 3, 85, 4, 11, 19, 48, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 32, 105, 115, 32, 105, 110, 99, 111, 114, 112, 111, 114, 97, 116, 101, 100, 32, 98, 121, 32, 114, 101, 102, 101, 114, 101, 110, 99, 101, 49, 31, 48, 29, 6, 3, 85, 4, 11, 19, 22, 40, 99, 41, 32, 50, 48, 48, 56, 32, 69, 110, 116, 114, 117, 115, 116, 44, 32, 73, 110, 99, 46, 49, 46, 48, 44, 6, 3, 85, 4, 3, 19, 37, 69, 110, 116, 114, 117, 115, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 45, 32, 76, 49, 66, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -36, 33, -11, 104, -7, 122, -50, -121, -14, 120, -33, -40, 59, 77, 6, 125, -58, 36, -28, -87, -51, -99, 1, 86, -28, -10, 113, 23, -86, 127, 117, 34, 24, -28, 116, 109, 27, 62, 86, -43, -79, -90, 30, -35, 89, 38, 83, -54, 6, -26, -70, 11, 111, 55, -69, -88, -58, -100, 21, 59, 6, 27, -121, 12, -62, 26, 77, -45, -127, -82, -37, 80, 101, -91, 58, 100, 79, 48, 52, -102, 43, -87, 31, -3, 43, -47, 56, 113, 25, 104, -14, -114, -21, 123, -55, 64, 60, 72, -60, 25, -79, -73, 16, 37, -17, 68, -89, -26, 119, -101, 125, 34, -102, -34, -40, 94, -39, -61, -50, -55, 113, 34, -69, -82, -17, 5, -42, -14, 23, -25, 86, 120, -31, 83, 5, 74, 38, 115, -72, -57, 73, 103, -109, 35, 15, 86, -78, -113, -35, -55, 89, 5, -27, 99, 21, -76, -121, 126, 64, 70, -23, -75, 0, 123, 3, -76, 13, -28, -106, 103, 44, -34, 27, 89, 11, 26, 31, -72, 99, 68, -82, -63, -41, 68, -121, -60, -111, 89, -100, 0, 67, 109, -58, -33, 10, -80, -79, 4, -51, -2, -66, 48, 94, 58, 37, 114, -35, -94, 62, -19, 70, 58, -57, -92, 92, 92, -28, 37, -14, 19, 7, -24, -82, -38, -101, 25, -101, -94, -39, 96, -99, -50, -112, 71, 106, 97, 123, 64, -24, 20, -62, -2, 47, -124, 90, 102, 23, -64, -105, -45, 73, 56, -34, 99, 2, -97, 2, 3, 1, 0, 1, -93, -126, 1, 38, 48, -126, 1, 34, 48, 14, 6, 3, 85, 29, 15, 1, 1, -1, 4, 4, 3, 2, 1, 6, 48, 15, 6, 3, 85, 29, 19, 1, 1, -1, 4, 5, 48, 3, 1, 1, -1, 48, 51, 6, 8, 43, 6, 1, 5, 5, 7, 1, 1, 4, 39, 48, 37, 48, 35, 6, 8, 43, 6, 1, 5, 5, 7, 48, 1, -122, 23, 104, 116, 116, 112, 58, 47, 47, 111, 99, 115, 112, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 48, 50, 6, 3, 85, 29, 31, 4, 43, 48, 41, 48, 39, -96, 37, -96, 35, -122, 33, 104, 116, 116, 112, 58, 47, 47, 99, 114, 108, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 50, 48, 52, 56, 99, 97, 46, 99, 114, 108, 48, 59, 6, 3, 85, 29, 32, 4, 52, 48, 50, 48, 48, 6, 4, 85, 29, 32, 0, 48, 40, 48, 38, 6, 8, 43, 6, 1, 5, 5, 7, 2, 1, 22, 26, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, -11, -14, -106, -120, 125, 13, -13, 42, -7, 78, -25, 52, -96, -67, 70, 126, 19, -42, 22, -56, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 25, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 12, 48, 10, 27, 4, 86, 55, 46, 49, 3, 2, 0, -127, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 11, 37, 60, 88, -6, -114, -36, -94, 66, 59, 118, 113, 110, 108, -44, 79, 43, -71, 83, 92, -78, 88, -71, -79, -36, 111, 26, -28, -29, -60, 80, -14, 65, -126, -70, -12, 125, -57, -63, -7, -6, -116, 83, -65, -71, 98, -73, 73, -29, 29, 10, -4, 31, -42, -60, 118, 106, -109, -53, 119, 30, 44, 127, -48, 63, 22, 99, 76, 114, 76, 103, 96, 15, -8, -128, -42, -89, -102, -54, -94, 51, -111, 15, 68, -78, 102, 61, -114, 104, 12, 64, -123, 18, 55, -111, -71, -126, 119, 52, 89, 45, 92, -33, -126, 110, 44, -74, 122, -46, 4, -112, 103, 104, 75, 112, -4, 45, -72, -1, -112, 100, 111, 126, -111, -9, -47, 71, 51, -13, 91, -72, 88, 46, 33, -40, 117, 96, 27, 19, -52, -8, -78, -88, -6, 106, -87, 42, 90, 79, 69, -123, 64, -76, -35, 52, 5, -73, 112, -54, 1, -17, -31, -127, -25, 17, 80, -37, 62, -30, -41, 16, 46, 106, 21, 127, -73, -44, -93, 98, -78, -119, 105, 97, 87, -58, 127, -114, -98, -44, 36, 122, -13, -95, 67, 95, -96, 122, -119, -36, 89, -51, 125, -41, 117, -89, -68, 83, -43, 71, 53, -58, 49, 48, 32, -97, -101, -70, -75, -125, -26, -119, 85, 1, 77, -111, 59, -42, -119, 53, -121, 60, -125, 107, 122, 41, -126, -44, 75, -44, -26, 22, 116, -80, 1, 16, -85, 105, 6, 20, 55, 123, -9, 102, 48, 58, -59 },
-            new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 },
-    };
+    private static final byte[] T61STRING_CERT = new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 };
 
     /**
-     * ASN1-encoded trusted certificate #946059622 for Entrust.net. This
-     * certificate uses the TELETEX encoding for its X509 name.
+     * Confirm DRLCertFactory uses a non-hex format for T61String encoding: http://b/2102191
      */
-    private final byte[] trustedCert = new byte[] { 48, -126, 4, 92, 48, -126, 3, 68, -96, 3, 2, 1, 2, 2, 4, 56, 99, -71, 102, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, 30, 23, 13, 57, 57, 49, 50, 50, 52, 49, 55, 53, 48, 53, 49, 90, 23, 13, 49, 57, 49, 50, 50, 52, 49, 56, 50, 48, 53, 49, 90, 48, -127, -76, 49, 20, 48, 18, 6, 3, 85, 4, 10, 19, 11, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 49, 64, 48, 62, 6, 3, 85, 4, 11, 20, 55, 119, 119, 119, 46, 101, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 47, 67, 80, 83, 95, 50, 48, 52, 56, 32, 105, 110, 99, 111, 114, 112, 46, 32, 98, 121, 32, 114, 101, 102, 46, 32, 40, 108, 105, 109, 105, 116, 115, 32, 108, 105, 97, 98, 46, 41, 49, 37, 48, 35, 6, 3, 85, 4, 11, 19, 28, 40, 99, 41, 32, 49, 57, 57, 57, 32, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 76, 105, 109, 105, 116, 101, 100, 49, 51, 48, 49, 6, 3, 85, 4, 3, 19, 42, 69, 110, 116, 114, 117, 115, 116, 46, 110, 101, 116, 32, 67, 101, 114, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 65, 117, 116, 104, 111, 114, 105, 116, 121, 32, 40, 50, 48, 52, 56, 41, 48, -126, 1, 34, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 1, 5, 0, 3, -126, 1, 15, 0, 48, -126, 1, 10, 2, -126, 1, 1, 0, -83, 77, 75, -87, 18, -122, -78, -22, -93, 32, 7, 21, 22, 100, 42, 43, 75, -47, -65, 11, 74, 77, -114, -19, -128, 118, -91, 103, -73, 120, 64, -64, 115, 66, -56, 104, -64, -37, 83, 43, -35, 94, -72, 118, -104, 53, -109, -117, 26, -99, 124, 19, 58, 14, 31, 91, -73, 30, -49, -27, 36, 20, 30, -79, -127, -87, -115, 125, -72, -52, 107, 75, 3, -15, 2, 12, -36, -85, -91, 64, 36, 0, 127, 116, -108, -95, -99, 8, 41, -77, -120, 11, -11, -121, 119, -99, 85, -51, -28, -61, 126, -41, 106, 100, -85, -123, 20, -122, -107, 91, -105, 50, 80, 111, 61, -56, -70, 102, 12, -29, -4, -67, -72, 73, -63, 118, -119, 73, 25, -3, -64, -88, -67, -119, -93, 103, 47, -58, -97, -68, 113, 25, 96, -72, 45, -23, 44, -55, -112, 118, 102, 123, -108, -30, -81, 120, -42, 101, 83, 93, 60, -42, -100, -78, -49, 41, 3, -7, 47, -92, 80, -78, -44, 72, -50, 5, 50, 85, -118, -3, -78, 100, 76, 14, -28, -104, 7, 117, -37, 127, -33, -71, 8, 85, 96, -123, 48, 41, -7, 123, 72, -92, 105, -122, -29, 53, 63, 30, -122, 93, 122, 122, 21, -67, -17, 0, -114, 21, 34, 84, 23, 0, -112, 38, -109, -68, 14, 73, 104, -111, -65, -8, 71, -45, -99, -107, 66, -63, 14, 77, -33, 111, 38, -49, -61, 24, 33, 98, 102, 67, 112, -42, -43, -64, 7, -31, 2, 3, 1, 0, 1, -93, 116, 48, 114, 48, 17, 6, 9, 96, -122, 72, 1, -122, -8, 66, 1, 1, 4, 4, 3, 2, 0, 7, 48, 31, 6, 3, 85, 29, 35, 4, 24, 48, 22, -128, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 3, 85, 29, 14, 4, 22, 4, 20, 85, -28, -127, -47, 17, -128, -66, -40, -119, -71, 8, -93, 49, -7, -95, 36, 9, 22, -71, 112, 48, 29, 6, 9, 42, -122, 72, -122, -10, 125, 7, 65, 0, 4, 16, 48, 14, 27, 8, 86, 53, 46, 48, 58, 52, 46, 48, 3, 2, 4, -112, 48, 13, 6, 9, 42, -122, 72, -122, -9, 13, 1, 1, 5, 5, 0, 3, -126, 1, 1, 0, 89, 71, -84, 33, -124, -118, 23, -55, -100, -119, 83, 30, -70, -128, -123, 26, -58, 60, 78, 62, -79, -100, -74, 124, -58, -110, 93, 24, 100, 2, -29, -45, 6, 8, 17, 97, 124, 99, -29, 43, -99, 49, 3, 112, 118, -46, -93, 40, -96, -12, -69, -102, 99, 115, -19, 109, -27, 42, -37, -19, 20, -87, 43, -58, 54, 17, -48, 43, -21, 7, -117, -91, -38, -98, 92, 25, -99, 86, 18, -11, 84, 41, -56, 5, -19, -78, 18, 42, -115, -12, 3, 27, -1, -25, -110, 16, -121, -80, 58, -75, -61, -99, 5, 55, 18, -93, -57, -12, 21, -71, -43, -92, 57, 22, -101, 83, 58, 35, -111, -15, -88, -126, -94, 106, -120, 104, -63, 121, 2, 34, -68, -86, -90, -42, -82, -33, -80, 20, 95, -72, -121, -48, -35, 124, 127, 123, -1, -81, 28, -49, -26, -37, 7, -83, 94, -37, -123, -99, -48, 43, 13, 51, -37, 4, -47, -26, 73, 64, 19, 43, 118, -5, 62, -23, -100, -119, 15, 21, -50, 24, -80, -123, 120, 33, 79, 107, 79, 14, -6, 54, 103, -51, 7, -14, -1, 8, -48, -30, -34, -39, -65, 42, -81, -72, -121, -122, 33, 60, 4, -54, -73, -108, 104, 127, -49, 60, -23, -104, -41, 56, -1, -20, -64, -39, 80, -16, 46, 75, 88, -82, 70, 111, -48, 46, -61, 96, -38, 114, 85, 114, -67, 76, 69, -98, 97, -70, -65, -124, -127, -110, 3, -47, -46, 105, 124, -59 };
+    public void testGetName() throws Exception {
+        CertificateFactory certFactBC = CertificateFactory.getInstance("X.509", "BC");
+        CertificateFactory certFactDRL = CertificateFactory.getInstance("X.509", "DRLCertFactory");
+
+        X509Certificate certBC = (X509Certificate)
+                certFactBC.generateCertificate(new ByteArrayInputStream(T61STRING_CERT));
+        X509Certificate certDRL = (X509Certificate)
+                certFactDRL.generateCertificate(new ByteArrayInputStream(T61STRING_CERT));
+
+        assertEquals(certBC, certDRL);
+
+        assertEquals(certBC.getSubjectX500Principal(), certBC.getSubjectX500Principal());
+        assertEquals(certDRL.getIssuerX500Principal(), certDRL.getIssuerX500Principal());
+
+        assertEquals(certBC.getSubjectX500Principal(), certDRL.getSubjectX500Principal());
+        assertEquals(certBC.getIssuerX500Principal(), certDRL.getIssuerX500Principal());
+
+        String[] formats = {
+            X500Principal.CANONICAL,
+            X500Principal.RFC1779,
+            X500Principal.RFC2253
+        };
+        for (String format : formats) {
+            assertEquals(certBC.getSubjectX500Principal().getName(format),
+                         certDRL.getSubjectX500Principal().getName(format));
+            assertEquals(certBC.getIssuerX500Principal().getName(format),
+                         certDRL.getIssuerX500Principal().getName(format));
+        }
+        String expected = ""
+                + "cn=entrust.net certification authority (2048),"
+                + "ou=(c) 1999 entrust.net limited,"
+                + "ou=www.entrust.net/cps_2048 incorp. by ref. (limits liab.),"
+                + "o=entrust.net";
+        assertEquals(expected,
+                     certBC.getSubjectX500Principal().getName(X500Principal.CANONICAL));
+
+    }
+}
+
+class SerializableTester<T> {
 
-    public void testTrustAndRemoteCertificatesWithDifferentEncodings()
-            throws IOException, CertificateException, KeyStoreException,
-            InvalidAlgorithmParameterException, CertPathValidatorException {
+    private final String golden;
+    private final T value;
 
-        X509CertPathImpl certPath = new X509CertPathImpl(Arrays.asList(
-                new X509CertImpl(serviceSprintComCertChain[0]),
-                new X509CertImpl(serviceSprintComCertChain[1]),
-                new X509CertImpl(serviceSprintComCertChain[2])));
+    public SerializableTester(T value, String golden) {
+        this.golden = golden;
+        this.value = value;
+    }
+
+    protected void verify(T deserialized) {}
+
+    public void test() {
+        try {
+            if (golden == null || golden.length() == 0) {
+                fail("No golden value supplied! Consider using this: "
+                        + hexEncode(serialize(value)));
+            }
+
+            // just a sanity check! if this fails, verify() is probably broken
+            verify(value);
+
+            @SuppressWarnings("unchecked") // deserialize should return the proper type
+            T deserialized = (T) deserialize(hexDecode(golden));
+            assertEquals("User-constructed value doesn't equal deserialized golden value",
+                    value, deserialized);
+            verify(deserialized);
+
+            @SuppressWarnings("unchecked") // deserialize should return the proper type
+            T reserialized = (T) deserialize(serialize(value));
+            assertEquals("User-constructed value doesn't equal itself, reserialized",
+                    value, reserialized);
+            verify(reserialized);
 
-        Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
-        trustAnchors.add(new TrustAnchor(new X509CertificateObject(
-                new X509CertificateStructure(
-                        (ASN1Sequence) new ASN1InputStream(trustedCert).readObject())), null));
+        } catch (Exception e) {
+            Error failure = new AssertionFailedError();
+            failure.initCause(e);
+            throw failure;
+        }
+    }
+
+    private byte[] serialize(Object object) throws IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        new ObjectOutputStream(out).writeObject(object);
+        return out.toByteArray();
+    }
 
-        IndexedPKIXParameters indexedPKIXParameters = new IndexedPKIXParameters(trustAnchors);
-        indexedPKIXParameters.setRevocationEnabled(false);
+    private Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
+        ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
+        Object result = in.readObject();
+        assertEquals(-1, in.read());
+        return result;
+    }
+
+    private String hexEncode(byte[] bytes) {
+        StringBuilder result = new StringBuilder(bytes.length * 2);
+        for (byte b : bytes) {
+            result.append(String.format("%02x", b));
+        }
+        return result.toString();
+    }
 
-        new PKIXCertPathValidatorSpi().engineValidate(certPath, indexedPKIXParameters);
-        // completing normally indicates that the certificate was valid
+    private byte[] hexDecode(String s) {
+        byte[] result = new byte[s.length() / 2];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = (byte) Integer.parseInt(s.substring(i*2, i*2 + 2), 16);
+        }
+        return result;
     }
 }
index 21929bf..f545276 100644 (file)
@@ -39,16 +39,13 @@ import java.security.AccessControlContext;
 import java.security.AccessController;
 import java.security.ProtectionDomain;
 
-import org.apache.harmony.security.tests.support.acl.PrincipalImpl;
-
-
 /**
  * Tests for <code>Subject</code> class constructors and methods.
- * 
+ *
  */
-@TestTargetClass(Subject.class) 
+@TestTargetClass(Subject.class)
 public class SubjectTest extends TestCase {
-    
+
     SecurityManager old;
 
     @Override
@@ -64,7 +61,7 @@ public class SubjectTest extends TestCase {
     }
 
     /**
-     * @tests javax.security.auth.Subject#Subject() 
+     * @tests javax.security.auth.Subject#Subject()
      */
     @TestTargetNew(
         level = TestLevel.COMPLETE,
@@ -83,83 +80,7 @@ public class SubjectTest extends TestCase {
             fail("Unexpected exception: " + e);
         }
     }
-    
-    /**
-     * @tests javax.security.auth.Subject#Subject(boolean readOnly,
-     *                                            Set<? extends Principal> principals,
-     *                                            Set<?> pubCredentials,
-     *                                            Set<?> privCredentials)
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "Subject",
-        args = {boolean.class, Set.class, Set.class, Set.class}
-    )
-    public void test_Constructor_02() {
-        Set <Principal> principal = new HashSet<Principal>();
-        Set <Object> pubCredentials = new HashSet<Object>();
-        Set <Object> privCredentials = new HashSet<Object>();
-        Principal pr1 = new PrincipalImpl("TestPrincipal1");
-        Principal pr2 = new PrincipalImpl("TestPrincipal2");
-        principal.add(pr1);
-        principal.add(pr2);
-        Object pubCredential1 = new Object();
-        Object pubCredential2 = new Object();
-        pubCredentials.add(pubCredential1);
-        pubCredentials.add(pubCredential2);
-        Object privCredential1 = new Object();
-        Object privCredential2 = new Object();
-        privCredentials.add(privCredential1);
-        privCredentials.add(privCredential2);
-        
-        try {
-            Subject s = new Subject(true, principal, pubCredentials, privCredentials);
-            assertNotNull("Null object returned", s);
-            assertTrue("Not read-only object", s.isReadOnly());
-            assertFalse("Set of principal is empty", s.getPrincipals().isEmpty());
-            assertFalse("Set of private credentials is empty", s.getPrivateCredentials().isEmpty());
-            assertFalse("Set of public credentials is empty", s.getPublicCredentials().isEmpty());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Subject s = new Subject(false, principal, pubCredentials, privCredentials);
-            assertNotNull("Null object returned", s);
-            assertFalse("Read-only object", s.isReadOnly());
-            assertFalse("Set of principal is empty", s.getPrincipals().isEmpty());
-            assertFalse("Set of private credentials is empty", s.getPrivateCredentials().isEmpty());
-            assertFalse("Set of public credentials is empty", s.getPublicCredentials().isEmpty());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Subject s = new Subject(true, null, pubCredentials, privCredentials);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Subject s = new Subject(true, principal, null, privCredentials);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Subject s = new Subject(true, principal, pubCredentials, null);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Subject s = new Subject(true, null, null, null);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-    }
-    
+
     /**
      * @tests javax.security.auth.Subject#doAs(Subject subject, PrivilegedAction action)
      */
@@ -173,44 +94,26 @@ public class SubjectTest extends TestCase {
         Subject subj = new Subject();
         PrivilegedAction<Object> pa = new myPrivilegedAction();
         PrivilegedAction<Object> paNull = null;
-        
+
         try {
             Object obj = Subject.doAs(null, pa);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAs(subj, pa);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAs(subj, paNull);
             fail("NullPointerException wasn't thrown");
         } catch (NullPointerException npe) {
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "doAs".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            Object obj = Subject.doAs(subj, pa);
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        }
     }
-    
+
     /**
      * @tests javax.security.auth.Subject#doAs(Subject subject, PrivilegedExceptionAction action)
      */
@@ -224,19 +127,19 @@ public class SubjectTest extends TestCase {
         Subject subj = new Subject();
         PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
         PrivilegedExceptionAction<Object> peaNull = null;
-        
+
         try {
             Object obj = Subject.doAs(null, pea);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAs(subj, pea);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAs(subj, peaNull);
             fail("NullPointerException wasn't thrown");
@@ -244,7 +147,7 @@ public class SubjectTest extends TestCase {
         } catch (Exception e) {
             fail(e + " was thrown instead of NullPointerException");
         }
-        
+
         try {
             Subject.doAs(subj, new PrivilegedExceptionAction<Object>(){
                 public Object run() throws PrivilegedActionException {
@@ -254,30 +157,10 @@ public class SubjectTest extends TestCase {
             fail("PrivilegedActionException wasn't thrown");
         } catch (PrivilegedActionException e) {
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "doAs".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            Object obj = Subject.doAs(subj, pea);
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        } catch (Exception e) {
-            fail(e + " was thrown instead of SecurityException");
-        }
     }
-    
+
     /**
-     * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject, 
+     * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
      *                                                   PrivilegedAction action,
      *                                                   AccessControlContext acc)
      */
@@ -292,46 +175,28 @@ public class SubjectTest extends TestCase {
         PrivilegedAction<Object> pa = new myPrivilegedAction();
         PrivilegedAction<Object> paNull = null;
         AccessControlContext acc = AccessController.getContext();
-        
+
         try {
             Object obj = Subject.doAsPrivileged(null, pa, acc);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAsPrivileged(subj, pa, acc);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAsPrivileged(subj, paNull, acc);
             fail("NullPointerException wasn't thrown");
         } catch (NullPointerException npe) {
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "doAsPrivileged".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            Object obj = Subject.doAsPrivileged(subj, pa, acc);
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        }
     }
-    
+
     /**
-     * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject, 
+     * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
      *                                                   PrivilegedExceptionAction action,
      *                                                   AccessControlContext acc)
      */
@@ -346,19 +211,19 @@ public class SubjectTest extends TestCase {
         PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
         PrivilegedExceptionAction<Object> peaNull = null;
         AccessControlContext acc = AccessController.getContext();
-        
+
         try {
             Object obj = Subject.doAsPrivileged(null, pea, acc);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAsPrivileged(subj, pea, acc);
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
+
         try {
             Object obj = Subject.doAsPrivileged(subj, peaNull, acc);
             fail("NullPointerException wasn't thrown");
@@ -366,7 +231,7 @@ public class SubjectTest extends TestCase {
         } catch (Exception e) {
             fail(e + " was thrown instead of NullPointerException");
         }
-        
+
         try {
             Subject.doAsPrivileged(subj, new PrivilegedExceptionAction<Object>(){
                 public Object run() throws PrivilegedActionException {
@@ -376,220 +241,8 @@ public class SubjectTest extends TestCase {
             fail("PrivilegedActionException wasn't thrown");
         } catch (PrivilegedActionException e) {
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "doAsPrivileged".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            Object obj = Subject.doAsPrivileged(subj, pea, acc);
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        } catch (Exception e) {
-            fail(e + " was thrown instead of SecurityException");
-        }
-    }
-    
-    /**
-     * @tests javax.security.auth.Subject#equals(Object o)
-     */
-    @TestTargetNew(
-        level = TestLevel.SUFFICIENT,
-        notes = "SecurityException wasn't tested",
-        method = "equals",
-        args = {Object.class}
-    )
-    public void test_equals() {
-        Set <Principal> principal = new HashSet<Principal>();
-        Set <Principal> principal1 = new HashSet<Principal>();
-        Set <Object> pubCredentials = new HashSet<Object>();
-        Set <Object> privCredentials = new HashSet<Object>();
-        Principal pr1 = new PrincipalImpl("TestPrincipal1");
-        Principal pr2 = new PrincipalImpl("TestPrincipal2");
-        principal.add(pr1);
-        principal.add(pr2);
-        principal1.add(pr1);
-        Object pubCredential1 = new Object();
-        Object pubCredential2 = new Object();
-        pubCredentials.add(pubCredential1);
-        pubCredentials.add(pubCredential2);
-        Object privCredential1 = new Object();
-        Object privCredential2 = new Object();
-        privCredentials.add(privCredential1);
-        privCredentials.add(privCredential2);
-        
-        Subject s1 = new Subject(true, principal, pubCredentials, privCredentials);
-        Subject s2 = new Subject(true, principal1, pubCredentials, privCredentials);
-        Subject s3 = new Subject(true, principal, pubCredentials, privCredentials);
-        
-        try {
-            assertTrue(s1.equals(s1));
-            assertFalse(s1.equals(s2));
-            assertTrue(s1.equals(s3));
-            assertFalse(s1.equals(new Object()));
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-               
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof PrivateCredentialPermission
-                        && "equals".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            s1.equals(s1);
-            //fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        } 
-    }
-    
-    /**
-     * @tests javax.security.auth.Subject#getPrincipals()
-     * @tests javax.security.auth.Subject#getPrivateCredentials()
-     * @tests javax.security.auth.Subject#getPublicCredentials()
-     * @tests javax.security.auth.Subject#isReadOnly()
-     * @tests javax.security.auth.Subject#setReadOnly()
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPrincipals",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPrivateCredentials",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPublicCredentials",
-            args = {}
-        )
-    })
-    public void test_getPrincipals() {
-        Set <Principal> principal = new HashSet<Principal>();
-        Set <Object> pubCredentials = new HashSet<Object>();
-        Set <Object> privCredentials = new HashSet<Object>();
-        Principal pr1 = new PrincipalImpl("TestPrincipal1");
-        Principal pr2 = new PrincipalImpl("TestPrincipal2");
-        principal.add(pr1);
-        principal.add(pr2);
-        Object pubCredential1 = new Object();
-        pubCredentials.add(pubCredential1);
-        Object privCredential1 = new Object();
-        Object privCredential2 = new Object();
-        privCredentials.add(privCredential1);
-        privCredentials.add(privCredential2);
-        
-        Subject s = new Subject(false, principal, pubCredentials, privCredentials);
-        
-        try {
-            Set<Principal> pr = s.getPrincipals();
-            assertNotNull(pr);
-            assertEquals(principal.size(), pr.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Set<Object> privC = s.getPrivateCredentials();
-            assertNotNull(privC);
-            assertEquals(privCredentials.size(), privC.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Set<Object> pubC = s.getPublicCredentials();
-            assertNotNull(pubC);
-            assertEquals(pubCredentials.size(), pubC.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests javax.security.auth.Subject#isReadOnly()
-     * @tests javax.security.auth.Subject#setReadOnly()
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "isReadOnly",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "setReadOnly",
-            args = {}
-        )
-    })
-    public void test_ReadOnly() {
-        Set <Principal> principal = new HashSet<Principal>();
-        Set <Object> pubCredentials = new HashSet<Object>();
-        Set <Object> privCredentials = new HashSet<Object>();
-        Principal pr1 = new PrincipalImpl("TestPrincipal1");
-        Principal pr2 = new PrincipalImpl("TestPrincipal2");
-        principal.add(pr1);
-        principal.add(pr2);
-        Object pubCredential1 = new Object();
-        pubCredentials.add(pubCredential1);
-        Object privCredential1 = new Object();
-        Object privCredential2 = new Object();
-        privCredentials.add(privCredential1);
-        privCredentials.add(privCredential2);
-        
-        Subject s = new Subject(false, principal, pubCredentials, privCredentials);
-        
-        try {
-            assertFalse(s.isReadOnly());
-            s.setReadOnly();
-            assertTrue(s.isReadOnly());
-        } catch (Exception e) {
-            fail("Unexpected exception " + e);
-        }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "setReadOnly".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager ss = new TestSecurityManager();
-        System.setSecurityManager(ss);
-        try {
-            s.setReadOnly();
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        }
     }
-    
+
     /**
      * @tests javax.security.auth.Subject#getSubject(AccessControlContext acc)
      */
@@ -602,32 +255,14 @@ public class SubjectTest extends TestCase {
     public void test_getSubject() {
         Subject subj = new Subject();
         AccessControlContext acc = new AccessControlContext(new ProtectionDomain[0]);
-        
+
         try {
             assertNull(Subject.getSubject(acc));
         } catch (Exception e) {
             fail("Unexpected exception " + e);
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "getSubject".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            Subject.getSubject(acc);
-            fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        } 
     }
-    
+
     /**
      * @tests javax.security.auth.Subject#toString()
      */
@@ -639,14 +274,14 @@ public class SubjectTest extends TestCase {
     )
     public void test_toString() {
         Subject subj = new Subject();
-        
+
         try {
             assertNotNull("Null returned", subj.toString());
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
     }
-    
+
     /**
      * @tests javax.security.auth.Subject#hashCode()
      */
@@ -658,115 +293,12 @@ public class SubjectTest extends TestCase {
     )
     public void test_hashCode() {
         Subject subj = new Subject();
-        
+
         try {
             assertNotNull("Null returned", subj.hashCode());
         } catch (Exception e) {
             fail("Unexpected exception: " + e);
         }
-        
-        class TestSecurityManager extends SecurityManager {
-            @Override
-            public void checkPermission(Permission permission) {
-                if (permission instanceof AuthPermission
-                        && "hashCode".equals(permission.getName())) {
-                    throw new SecurityException();
-                }
-                super.checkPermission(permission);
-            }
-        }
-        TestSecurityManager s = new TestSecurityManager();
-        System.setSecurityManager(s);
-        try {
-            subj.hashCode();
-            //fail("SecurityException wasn't thrown");
-        } catch (SecurityException se) {
-        }
-    }
-    
-    /**
-     * @tests javax.security.auth.Subject#getPrincipals(Class<T> c)
-     * @tests javax.security.auth.Subject#getPrivateCredentials(Class<T> c)
-     * @tests javax.security.auth.Subject#getPublicCredentials(Class<T> c)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPrincipals",
-            args = {Class.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.SUFFICIENT,
-            notes = "",
-            method = "getPrivateCredentials",
-            args = {Class.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.SUFFICIENT,
-            notes = "",
-            method = "getPublicCredentials",
-            args = {Class.class}
-        )
-    })
-    public void test_getPrincipals_Class() {
-        Set <Principal> principal = new HashSet<Principal>();
-        Set <Object> pubCredentials = new HashSet<Object>();
-        Set <Object> privCredentials = new HashSet<Object>();
-        Principal pr1 = new PrincipalImpl("TestPrincipal1");
-        Principal pr2 = new PrincipalImpl("TestPrincipal2");
-        principal.add(pr1);
-        principal.add(pr2);
-        Object pubCredential1 = new Object();
-        pubCredentials.add(pubCredential1);
-        Object privCredential1 = new Object();
-        Object privCredential2 = new Object();
-        privCredentials.add(privCredential1);
-        privCredentials.add(privCredential2);
-        
-        Subject s = new Subject(true, principal, pubCredentials, privCredentials);
-        
-        try {
-            Set<Principal> pr = s.getPrincipals(null);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Set<Object> privC = s.getPrivateCredentials(null);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Set<Object> pubC = s.getPublicCredentials(null);
-            fail("NullPointerException wasn't thrown");
-        } catch (NullPointerException npe) {
-        }
-        
-        try {
-            Set<Principal> pr = s.getPrincipals(Principal.class);
-            assertNotNull(pr);
-            assertEquals(principal.size(), pr.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Set<Object> privC = s.getPrivateCredentials(Object.class);
-            assertNotNull(privC);
-            assertEquals(privCredentials.size(), privC.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        
-        try {
-            Set<Object> pubC = s.getPublicCredentials(Object.class);
-            assertNotNull(pubC);
-            assertEquals(pubCredentials.size(), pubC.size());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
     }
 }
 
index 4b93980..e832f42 100644 (file)
@@ -39,11 +39,6 @@ public class AllTests {
         suite.addTestSuite(LastOwnerExceptionTest.class);
         suite.addTestSuite(NotOwnerException2Test.class);
         suite.addTestSuite(NotOwnerExceptionTest.class);
-        suite.addTestSuite(IPermissionTest.class);
-        suite.addTestSuite(IGroupTest.class);
-        suite.addTestSuite(IOwnerTest.class);        
-        suite.addTestSuite(IAclEntryTest.class);
-        suite.addTestSuite(IAclTest.class);
 
         // $JUnit-END$
         return suite;
diff --git a/libcore/security/src/test/java/tests/security/acl/IAclEntryTest.java b/libcore/security/src/test/java/tests/security/acl/IAclEntryTest.java
deleted file mode 100644 (file)
index 94ddf14..0000000
+++ /dev/null
@@ -1,213 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.security.acl;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.acl.AclEntry;
-import java.security.acl.Permission;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.apache.harmony.security.tests.support.acl.*;
-
-@TestTargetClass(AclEntry.class)
-public class IAclEntryTest extends TestCase {
-    
-    class MyAclEntry extends AclEntryImpl {
-        public MyAclEntry() {
-            super();
-        }
-        public MyAclEntry(Principal pr) {
-            super(pr);
-        }
-    }
-    
-    
-    /**
-     * @tests java.security.acl.AclEntry#addPermission(Permission permission) 
-     * @tests java.security.acl.AclEntry#checkPermission(Permission permission)
-     * @tests java.security.acl.AclEntry#removePermission(Permission permission)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "addPermission",
-            args = {java.security.acl.Permission.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "checkPermission",
-            args = {java.security.acl.Permission.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "removePermission",
-            args = {java.security.acl.Permission.class}
-        )
-    })
-    public void test_AclEntry01() {
-        Permission perm = new PermissionImpl("Permission_1");
-        MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
-        try {
-            assertTrue(ae.addPermission(perm));
-            assertFalse(ae.addPermission(perm));
-            assertTrue(ae.checkPermission(perm));
-            assertTrue(ae.removePermission(perm));
-            assertFalse(ae.removePermission(perm));
-            assertFalse(ae.checkPermission(perm));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.AclEntry#getPrincipal() 
-     * @tests java.security.acl.AclEntry#setPrincipal(Principal user)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPrincipal",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "setPrincipal",
-            args = {java.security.Principal.class}
-        )
-    })
-    public void test_AclEntry02() {
-        MyAclEntry ae = new MyAclEntry();
-        Principal mp = new PrincipalImpl("TestPrincipal");
-        try {
-            assertTrue(ae.setPrincipal(mp));
-            Principal p = ae.getPrincipal();
-            assertEquals("Names are not equal", p.getName(), mp.getName());
-            assertFalse(ae.setPrincipal(mp));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.AclEntry#setNegativePermissions() 
-     * @tests java.security.acl.AclEntry#isNegative()
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "setNegativePermissions",
-            args = {}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "isNegative",
-            args = {}
-        )
-    })
-    public void test_AclEntry03() {
-        MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
-        try {
-            assertFalse("isNegative() returns TRUE",ae.isNegative());
-            ae.setNegativePermissions();
-            assertTrue("isNegative() returns FALSE", ae.isNegative());
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.AclEntry#permissions() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "permissions",
-        args = {}
-    )
-    public void test_AclEntry04() {
-        MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
-        Permission perm = new PermissionImpl("Permission_1");
-        try {
-            Enumeration en = ae.permissions();
-            assertFalse("Not empty enumeration", en.hasMoreElements());
-            ae.addPermission(perm);
-            en = ae.permissions();
-            assertTrue("Eempty enumeration", en.hasMoreElements());
-            Vector v = new Vector();
-            while (en.hasMoreElements()) {
-                v.addElement(en.nextElement());
-            }
-            assertEquals(v.size(), 1);
-            assertEquals(v.elementAt(0).toString(), perm.toString());
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.AclEntry#toString() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "toString",
-        args = {}
-    )
-    public void test_AclEntry05() {
-        MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
-        try {
-            String res = ae.toString();
-            assertTrue(res.contains("TestPrincipal"));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.AclEntry#clone() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "clone",
-        args = {}
-    )
-    public void test_AclEntry06() {
-        MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
-        try {
-            assertEquals("Objects are not equal", ae.toString(), ae.clone().toString());
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-}
\ No newline at end of file
diff --git a/libcore/security/src/test/java/tests/security/acl/IAclTest.java b/libcore/security/src/test/java/tests/security/acl/IAclTest.java
deleted file mode 100644 (file)
index 65cb971..0000000
+++ /dev/null
@@ -1,230 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.security.acl;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.acl.Acl;
-import java.security.acl.AclEntry;
-import java.security.acl.NotOwnerException;
-import java.security.acl.Permission;
-import java.security.Principal;
-import java.util.Enumeration;
-import java.util.Vector;
-
-import org.apache.harmony.security.tests.support.acl.*;
-
-@TestTargetClass(Acl.class)
-public class IAclTest extends TestCase {
-    
-    class MyAcl extends AclImpl {
-        public MyAcl(Principal principal, String str) {
-            super(principal, str);
-        }
-    }
-
-    
-    /**
-     * @tests java.security.acl.Acl#addEntry(Principal caller, AclEntry entry)
-     * @tests java.security.acl.Acl#removeEntry(Principal caller, AclEntry entry)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "addEntry",
-            args = {java.security.Principal.class, java.security.acl.AclEntry.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "removeEntry",
-            args = {java.security.Principal.class, java.security.acl.AclEntry.class}
-        )
-    })
-    public void test_Acl01() {
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        String str = "TestName";
-        MyAcl acl = new MyAcl(pr, str);
-        AclEntry ae = new AclEntryImpl(pr);
-        try {
-            assertTrue(acl.addEntry(pr, ae));
-            assertFalse(acl.addEntry(pr, ae));
-            assertTrue(acl.removeEntry(pr, ae));
-            assertFalse(acl.removeEntry(pr, ae));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-        
-        try {
-            acl.addEntry(new PrincipalImpl("NewPrincipal"), ae);
-            fail("NotOwnerException was not thrown");
-        } catch (NotOwnerException noe) {
-            //expected
-        }
-        
-        try {
-            acl.removeEntry(new PrincipalImpl("NewPrincipal"), ae);
-            fail("NotOwnerException was not thrown");
-        } catch (NotOwnerException noe) {
-            //expected
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Acl#setName(Principal caller, String name)
-     * @tests java.security.acl.Acl#getName()
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "setName",
-            args = {java.security.Principal.class, java.lang.String.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getName",
-            args = {}
-        )
-    })
-    public void test_Acl02() {
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        String str = "TestName";
-        String newStr = "NewName";
-        MyAcl acl = new MyAcl(pr, str);
-        try {
-            assertEquals("Names are not equal", str, acl.getName());
-            acl.setName(pr, newStr);
-            assertEquals("Names are not equal", newStr, acl.getName());
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-        
-        try {
-            acl.setName(new PrincipalImpl("NewPrincipal"), str);
-            fail("NotOwnerException was not thrown");
-        } catch (NotOwnerException noe) {
-            //expected
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Acl#toString()
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "toString",
-        args = {}
-    )
-    public void test_Acl03() {
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        String str = "TestName";
-        MyAcl acl = new MyAcl(pr, str);
-        AclEntry ae = new AclEntryImpl(pr);
-        Permission perm = new PermissionImpl("Permission_1");
-        try {
-            ae.addPermission(perm);
-            acl.addEntry(pr, ae);
-            String res = acl.toString();
-            assertTrue(res.contains(perm.toString()));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Acl#entries()
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "entries",
-        args = {}
-    )
-    public void test_Acl04() {
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        String str = "TestName";
-        MyAcl acl = new MyAcl(pr, str);
-        AclEntry ae1 = new AclEntryImpl(pr);
-        try {
-            ae1.addPermission(new PermissionImpl("Permission_1"));
-            acl.addEntry(pr, ae1);
-            Enumeration en = acl.entries();
-            Vector v = new Vector();
-            while (en.hasMoreElements()) {
-                v.addElement(en.nextElement());
-            }
-            assertEquals(v.size(), 1);
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Acl#checkPermission(Principal principal, Permission permission)
-     * @tests java.security.acl.Acl#getPermissions(Principal principal)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "checkPermission",
-            args = {java.security.Principal.class, java.security.acl.Permission.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "getPermissions",
-            args = {java.security.Principal.class}
-        )
-    })
-    public void test_Acl05() {
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        String str = "TestName";
-        MyAcl acl = new MyAcl(pr, str);
-        AclEntry ae = new AclEntryImpl(pr);
-        Permission perm = new PermissionImpl("Permission_1");
-        try {
-            ae.addPermission(perm);
-            acl.addEntry(pr, ae);
-            
-            //checkPermission verification
-            assertTrue("Incorrect permission", acl.checkPermission(pr, perm));
-            assertFalse(acl.checkPermission(pr, new PermissionImpl("Permission_2")));
-            
-            //getPermissions
-            Enumeration en = acl.getPermissions(pr);
-            Vector v = new Vector();
-            while (en.hasMoreElements()) {
-                v.addElement(en.nextElement());
-            }
-            assertEquals(v.size(), 1);
-            assertEquals(v.elementAt(0).toString(), perm.toString());
-        } catch (Exception ex) {
-            fail("Exception " + ex + " was thrown");
-        }
-    }
-}
\ No newline at end of file
diff --git a/libcore/security/src/test/java/tests/security/acl/IGroupTest.java b/libcore/security/src/test/java/tests/security/acl/IGroupTest.java
deleted file mode 100644 (file)
index 47eac93..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.security.acl;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.acl.Group;
-import java.security.Principal;
-import java.util.Enumeration;
-
-import org.apache.harmony.security.tests.support.acl.*;
-
-@TestTargetClass(Group.class)
-public class IGroupTest extends TestCase {
-    
-    class MyGroup extends GroupImpl {
-        public MyGroup(String str) {
-            super(str);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Group#addMember(Principal user)
-     */
-    @TestTargets({
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "addMember",
-            args = {java.security.Principal.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "isMember",
-            args = {java.security.Principal.class}
-        ),
-        @TestTargetNew(
-            level = TestLevel.COMPLETE,
-            notes = "",
-            method = "removeMember",
-            args = {java.security.Principal.class}
-        )
-    })
-    public void test_addMember() {
-        MyGroup gr = new MyGroup("TestOwners");
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        try {
-            assertTrue(gr.addMember(pr));
-            assertFalse(gr.addMember(pr));
-            assertTrue(gr.isMember(pr));
-            assertTrue(gr.removeMember(pr));
-            assertFalse(gr.isMember(pr));
-            assertFalse(gr.removeMember(pr));
-        } catch (Exception e) {
-            fail("Unexpected exception " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Group#members()
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "members",
-        args = {}
-    )
-    public void test_members() {
-        MyGroup gr = new MyGroup("TestOwners");
-        Principal pr = new PrincipalImpl("TestPrincipal");
-        try {
-            Enumeration en = gr.members();
-            assertFalse("Not empty enumeration", en.hasMoreElements());
-            assertTrue(gr.addMember(pr));
-            assertTrue("Empty enumeration", en.hasMoreElements());
-        } catch (Exception e) {
-            fail("Unexpected exception " + e);
-        }
-    }
-}
\ No newline at end of file
diff --git a/libcore/security/src/test/java/tests/security/acl/IOwnerTest.java b/libcore/security/src/test/java/tests/security/acl/IOwnerTest.java
deleted file mode 100644 (file)
index 3cb222d..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.security.acl;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.acl.Owner;
-import java.security.Principal;
-import java.security.acl.NotOwnerException;
-import java.security.acl.LastOwnerException;
-
-import org.apache.harmony.security.tests.support.acl.*;
-
-@TestTargetClass(Owner.class)
-public class IOwnerTest extends TestCase {
-    
-    class MyOwner extends OwnerImpl {
-        public MyOwner(Principal pr) {
-            super(pr);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Owner#isOwner(Principal owner)
-     * 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "isOwner",
-        args = {java.security.Principal.class}
-    )
-    public void test_isOwner() {
-        MyOwner mo = new MyOwner(new PrincipalImpl("NewOwner"));
-        try {
-            assertFalse("Method returns TRUE", mo.isOwner(new PrincipalImpl("TestOwner")));
-            assertTrue("Method returns FALSE", mo.isOwner(new PrincipalImpl("NewOwner")));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Owner#addOwner(Principal caller, Principal owner)
-     * 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "addOwner",
-        args = {java.security.Principal.class, java.security.Principal.class}
-    )
-    public void test_addOwner() {
-        Principal p1 = new PrincipalImpl("Owner");
-        Principal p2 = new PrincipalImpl("AclOwner");
-        Principal pt = new PrincipalImpl("NewOwner");
-        MyOwner mo = new MyOwner(p1);
-        try {
-            //add new owner - TRUE expected
-            assertTrue("Method returns FALSE", mo.addOwner(p1, pt));
-            //add existent owner - FALSE expected
-            assertFalse("Method returns TRUE", mo.addOwner(p1, pt));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-        //exception case
-        try {
-            mo.addOwner(p2, pt);
-            fail("NotOwnerException was not thrown");
-        } catch (NotOwnerException noe) {
-            //expected
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Owner#deleteOwner(Principal caller, Principal owner)
-     * 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "deleteOwner",
-        args = {java.security.Principal.class, java.security.Principal.class}
-    )
-    public void test_deleteOwner() {
-        Principal caller = new PrincipalImpl("Owner");
-        Principal owner1 = new PrincipalImpl("NewOwner1");
-        Principal owner2 = new PrincipalImpl("NewOwner2");
-        Principal notCaller = new PrincipalImpl("AclOwner");
-        MyOwner mo = new MyOwner(caller);
-        
-        try {
-            if (!mo.isOwner(owner1))  mo.addOwner(caller, owner1);
-            if (!mo.isOwner(owner2))  mo.addOwner(caller, owner2);
-        } catch (Exception e) {
-            fail("Unexpected exception " + e + " was thrown for addOwner");
-        }
-        
-        try {
-            //remove existent owner - TRUE expected
-            assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner1));
-            assertFalse("Object presents in the owner list", mo.isOwner(owner1));
-            //remove owner which is not part of the list of owners - FALSE expected
-            assertFalse("Method returns TRUE", mo.deleteOwner(caller, owner1));
-            assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner2));
-        } catch (Exception ex) {
-            fail("Unexpected exception " + ex);
-        }
-        //exception case - NotOwnerException
-        try {
-            mo.deleteOwner(notCaller, owner1);
-            fail("NotOwnerException was not thrown");
-        } catch (NotOwnerException noe) {
-            //expected
-        } catch (Exception e) {
-            fail(e + " was thrown instead of NotOwnerException");
-        }
-        //exception case - LastOwnerException
-        try {
-            mo.deleteOwner(caller, owner2);
-            fail("LastOwnerException was not thrown");
-        } catch (LastOwnerException loe) {
-            //expected
-        } catch (Exception e) {
-            fail(e + " was thrown instead of LastOwnerException");
-        }
-    }
-}
\ No newline at end of file
diff --git a/libcore/security/src/test/java/tests/security/acl/IPermissionTest.java b/libcore/security/src/test/java/tests/security/acl/IPermissionTest.java
deleted file mode 100644 (file)
index 17cd7a9..0000000
+++ /dev/null
@@ -1,80 +0,0 @@
-/* 
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *     http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package tests.security.acl;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.acl.Permission;
-
-import org.apache.harmony.security.tests.support.acl.*;
-
-@TestTargetClass(Permission.class)
-public class IPermissionTest extends TestCase {
-    
-    class MyPermission extends PermissionImpl {
-        public MyPermission(String str) {
-            super(str);
-        }
-    }    
-    
-    /**
-     * @tests java.security.acl.Permission#equals(Object another)
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "equals",
-        args = {java.lang.Object.class}
-    )
-    public void test_equals() {
-        try {
-            MyPermission mp1 = new MyPermission("TestPermission");
-            MyPermission mp2 = new MyPermission("NewTestPermission");
-            Object another = new Object();
-            assertFalse(mp1.equals(another));
-            assertFalse(mp1.equals(mp2));
-            assertTrue(mp1.equals(new MyPermission("TestPermission")));
-        } catch (Exception e) {
-            fail("Unexpected exception - subtest1");
-        }
-    }
-    
-    /**
-     * @tests java.security.acl.Permission#toString()
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "toString",
-        args = {}
-    )
-    public void test_toString() {
-        try {
-            MyPermission obj = new MyPermission("TestPermission");
-            String res = obj.toString();
-            assertEquals(res, "TestPermission");
-        } catch (Exception e) {
-            fail("Unexpected exception - subtest2");
-        }
-    }
-}
\ No newline at end of file
index 749a5ab..1c76c1b 100644 (file)
@@ -80,7 +80,6 @@ public class AllTests {
         // Crashes on RI.
         // suite.addTestSuite(X509CertSelectorTest.class);
         suite.addTestSuite(X509Certificate2Test.class);
-        suite.addTestSuite(PolicyNodeTest.class);
 
         // $JUnit-END$
         return suite;
index 551fda6..b194c70 100644 (file)
@@ -36,9 +36,9 @@ import java.util.Collection;
 import java.util.Vector;
 
 import org.apache.harmony.security.tests.support.cert.MyCertificate;
+
 /**
- * Tests for <code>CollectionCertStoreParameters</code>
- * 
+ * Tests for <code>CollectionCertStoreParameters</code>.
  */
 @TestTargetClass(CollectionCertStoreParameters.class)
 public class CollectionCertStoreParametersTest extends TestCase {
@@ -49,8 +49,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #1 for <code>CollectionCertStoreParameters()</code> constructor<br>
-     * Assertion: Creates an instance of CollectionCertStoreParameters
-     * with the default parameter values (an empty and immutable Collection) 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -66,8 +64,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #2 for <code>CollectionCertStoreParameters</code> constructor<br>
-     * Assertion: Creates an instance of CollectionCertStoreParameters
-     * with the default parameter values (an empty and immutable Collection) 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -93,7 +89,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
     /**
      * Test #1 for <code>CollectionCertStoreParameters(Collection)</code>
      * constructor<br>
-     * Assertion: Creates an instance of CollectionCertStoreParameters 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -110,9 +105,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
     /**
      * Test #2 for <code>CollectionCertStoreParameters(Collection)</code>
      * constructor<br>
-     * Assertion: If the specified <code>Collection</code> contains an object
-     * that is not a <code>Certificate</code> or <code>CRL</code>, that object
-     * will be ignored by the Collection <code>CertStore</code>. 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -132,11 +124,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
     /**
      * Test #3 for <code>CollectionCertStoreParameters(Collection)</code>
      * constructor<br>
-     * Assertion: The Collection is not copied. Instead, a reference is used.
-     * This allows the caller to subsequently add or remove Certificates or
-     * CRLs from the Collection, thus changing the set of Certificates or CRLs
-     * available to the Collection CertStore. The Collection CertStore will
-     * not modify the contents of the Collection 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -149,7 +136,7 @@ public class CollectionCertStoreParametersTest extends TestCase {
         // create using empty collection
         CollectionCertStoreParameters cp =
             new CollectionCertStoreParameters(certificates);
-        // check that the reference is used 
+        // check that the reference is used
         assertTrue("isRefUsed_1", certificates == cp.getCollection());
         // check that collection still empty
         assertTrue("isEmpty", cp.getCollection().isEmpty());
@@ -163,8 +150,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
     /**
      * Test #4 for <code>CollectionCertStoreParameters(Collection)</code>
      * constructor<br>
-     * Assertion: <code>NullPointerException</code> - if
-     * <code>collection</code> is <code>null</code> 
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -182,7 +167,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #1 for <code>clone()</code> method<br>
-     * Assertion: Returns a copy of this object
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -203,8 +187,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #2 for <code>clone()</code> method<br>
-     * Assertion: ...only a reference to the <code>Collection</code>
-     * is copied, and not the contents
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -225,8 +207,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #3 for <code>clone()</code> method<br>
-     * Assertion: ...only a reference to the <code>Collection</code>
-     * is copied, and not the contents
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -248,7 +228,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #1 for <code>toString()</code> method<br>
-     * Assertion: returns the formatted string describing parameters
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -265,7 +244,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #2 for <code>toString()</code> method<br>
-     * Assertion: returns the formatted string describing parameters
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -284,7 +262,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #1 for <code>getCollection()</code> method<br>
-     * Assertion: returns the Collection (never null)
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
@@ -299,7 +276,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
 
     /**
      * Test #2 for <code>getCollection()</code> method<br>
-     * Assertion: returns the Collection (never null)
      */
     @TestTargetNew(
         level = TestLevel.PARTIAL_COMPLETE,
diff --git a/libcore/security/src/test/java/tests/security/cert/PolicyNodeTest.java b/libcore/security/src/test/java/tests/security/cert/PolicyNodeTest.java
deleted file mode 100644 (file)
index 6c075f9..0000000
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one or more
- *  contributor license agreements.  See the NOTICE file distributed with
- *  this work for additional information regarding copyright ownership.
- *  The ASF licenses this file to You under the Apache License, Version 2.0
- *  (the "License"); you may not use this file except in compliance with
- *  the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- */
-
-package tests.security.cert;
-
-import dalvik.annotation.TestTargets;
-import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
-import dalvik.annotation.TestTargetClass;
-
-import junit.framework.TestCase;
-
-import java.security.cert.PolicyNode;
-import java.security.cert.PolicyQualifierInfo;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Iterator;
-
-import org.apache.harmony.security.tests.support.cert.PolicyNodeImpl;
-
-/**
- * Tests for <code>java.security.cert.PolicyNode</code> fields and methods
- * 
- */
-@TestTargetClass(PolicyNode.class)
-public class PolicyNodeTest extends TestCase {
-    
-    private String validPolicy = "ValidPolicy";
-    private String anyPolicy = "2.5.29.32.0";
-    private boolean criticalityIndicator = true;
-    private HashSet hs = null;
-    
-    /**
-     * Returns valid DER encoding for the following ASN.1 definition
-     * (as specified in RFC 3280 -
-     *  Internet X.509 Public Key Infrastructure.
-     *  Certificate and Certificate Revocation List (CRL) Profile.
-     *  http://www.ietf.org/rfc/rfc3280.txt):
-     * 
-     *   PolicyQualifierInfo ::= SEQUENCE {
-     *      policyQualifierId       PolicyQualifierId,
-     *      qualifier               ANY DEFINED BY policyQualifierId
-     *   }
-     * 
-     * where policyQualifierId (OID) is
-     *      1.3.6.1.5.5.7.2.1
-     * and qualifier (IA5String) is
-     *      "http://www.qq.com/stmt.txt"
-     *      
-     * (data generated by own encoder during test development)
-     */
-    private static final byte[] getDerEncoding() {
-        // DO NOT MODIFY!
-        return  new byte[] {
-            (byte)0x30, (byte)0x26, // tag Seq, length
-              (byte)0x06, (byte)0x08, // tag OID, length
-                (byte)0x2b, (byte)0x06, (byte)0x01, (byte)0x05, // oid value 
-                (byte)0x05, (byte)0x07, (byte)0x02, (byte)0x01, // oid value
-              (byte)0x16, (byte)0x1a, // tag IA5String, length
-                (byte)0x68, (byte)0x74, (byte)0x74, (byte)0x70,  // IA5String value
-                (byte)0x3a, (byte)0x2f, (byte)0x2f, (byte)0x77,  // IA5String value
-                (byte)0x77, (byte)0x77, (byte)0x2e, (byte)0x71,  // IA5String value
-                (byte)0x71, (byte)0x2e, (byte)0x63, (byte)0x6f,  // IA5String value
-                (byte)0x6d, (byte)0x2f, (byte)0x73, (byte)0x74,  // IA5String value
-                (byte)0x6d, (byte)0x74, (byte)0x2e, (byte)0x74,  // IA5String value
-                (byte)0x78, (byte)0x74   // IA5String value
-        };
-    }
-    
-    protected void setUp() {
-        hs = new HashSet();
-        hs.add(new String("StringParameter1"));
-        hs.add(new String("StringParameter2"));
-        hs.add(new String("StringParameter3"));
-    }
-    
-    protected void setUp1() {
-        hs = new HashSet();
-        try {
-            hs.add(new PolicyQualifierInfo(getDerEncoding()));
-        } catch (Exception e) {
-            fail("Ezxception " + e + " for setUp1()");
-        }
-    }
-
-
-    class MyPolicyNode extends PolicyNodeImpl {
-        MyPolicyNode(PolicyNodeImpl policynode, String s, Set set, 
-                     boolean flag, Set set1, boolean flag1) {
-            super(policynode, s, set, flag, set1, flag1);
-        }
-    }
-
-    //
-    // Tests
-    //
-
-    /**
-     * @tests java.security.cert.PolicyNode#getDepth() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getDepth",
-        args = {}
-    )
-    public final void test_getDepth() {
-        MyPolicyNode pn = new MyPolicyNode(null, validPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.getDepth(), 0);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        MyPolicyNode pn1 = new MyPolicyNode(pn, validPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn1.getDepth(), 1);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#getValidPolicy() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getValidPolicy",
-        args = {}
-    )
-    public final void test_getValidPolicy() {
-        MyPolicyNode pn = new MyPolicyNode(null, null, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.getValidPolicy(), "");
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        pn = new MyPolicyNode(pn, validPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.getValidPolicy(), "ValidPolicy");
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        pn = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.getValidPolicy(), "2.5.29.32.0");
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#isCritical() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "isCritical",
-        args = {}
-    )
-    public final void test_isCritical() {
-        MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.isCritical(), true);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        criticalityIndicator = false;
-        pn = new MyPolicyNode(null, validPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertEquals(pn.isCritical(), false);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#getParent() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getParent",
-        args = {}
-    )
-    public final void test_getParent() {
-        MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            assertNull(pn.getParent());
-            assertEquals(pn.getDepth(), 0);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        MyPolicyNode pn1 = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            PolicyNode newPN = pn1.getParent();
-            assertEquals(newPN.getDepth(), 0);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-        MyPolicyNode pn2 = new MyPolicyNode(pn1, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            PolicyNode newPN = pn2.getParent();
-            assertEquals(newPN.getDepth(), 1);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#getExpectedPolicies() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getExpectedPolicies",
-        args = {}
-    )
-    public final void test_getExpectedPolicies() {
-        setUp();
-        MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, hs, true);
-        try {
-            Set res = pn.getExpectedPolicies();
-            assertEquals(res.size(), hs.size());
-            assertEquals(res, hs);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#getPolicyQualifiers() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getPolicyQualifiers",
-        args = {}
-    )
-    public final void test_getPolicyQualifiers() {
-        setUp1();
-        MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, hs, criticalityIndicator, null, true);
-        try {
-            Set res = pn.getPolicyQualifiers();
-            assertEquals(res.size(), hs.size());
-            assertEquals(res, hs);
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-    
-    /**
-     * @tests java.security.cert.PolicyNode#getChildren() 
-     */
-    @TestTargetNew(
-        level = TestLevel.COMPLETE,
-        notes = "",
-        method = "getChildren",
-        args = {}
-    )
-    public final void test_getChildren() {
-        MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
-        Iterator it = pn.getChildren();
-        try {
-            it.remove();
-            fail("UnsupportedOperationException was not thrown");
-        } catch (UnsupportedOperationException uoe) {
-            //expected
-        }
-        MyPolicyNode pn1 = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
-        try {
-            it = pn1.getChildren();
-            assertFalse(it.hasNext());
-        } catch (Exception e) {
-            fail("Unexpected exception: " + e);
-        }
-    }
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEntryImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEntryImpl.java
deleted file mode 100644 (file)
index 3d922df..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.Principal;\r
-import java.security.acl.*;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\r
-/**\r
- * Additional class for verification AclEntry interface \r
- */\r
-public class AclEntryImpl implements AclEntry {\r
-    \r
-    private Principal user;\r
-    private Vector permissionSet;\r
-    private boolean negative;\r
-\r
-    public AclEntryImpl(Principal principal) {\r
-        user = null;\r
-        permissionSet = new Vector(10, 10);\r
-        negative = false;\r
-        user = principal;\r
-    }\r
-\r
-    public AclEntryImpl() {\r
-        user = null;\r
-        permissionSet = new Vector(10, 10);\r
-        negative = false;\r
-    }\r
-\r
-    public boolean setPrincipal(Principal principal) {\r
-        if(user != null) {\r
-            return false;\r
-        } else {\r
-            user = principal;\r
-            return true;\r
-        }\r
-    }\r
-\r
-    public void setNegativePermissions() {\r
-        negative = true;\r
-    }\r
-\r
-    public boolean isNegative() {\r
-        return negative;\r
-    }\r
-\r
-    public boolean addPermission(Permission permission) {\r
-        if(permissionSet.contains(permission)) {\r
-            return false;\r
-        } else {\r
-            permissionSet.addElement(permission);\r
-            return true;\r
-        }\r
-    }\r
-\r
-    public boolean removePermission(Permission permission) {\r
-        return permissionSet.removeElement(permission);\r
-    }\r
-\r
-    public boolean checkPermission(Permission permission) {\r
-        return permissionSet.contains(permission);\r
-    }\r
-\r
-    public Enumeration permissions() {\r
-        return permissionSet.elements();\r
-    }\r
-\r
-    public String toString() {\r
-        StringBuffer stringbuffer = new StringBuffer();\r
-        if(negative)\r
-            stringbuffer.append("-");\r
-        else\r
-            stringbuffer.append("+");\r
-        if(user instanceof Group)\r
-            stringbuffer.append("Group.");\r
-        else\r
-            stringbuffer.append("User.");\r
-        stringbuffer.append((new StringBuilder()).append(user).append("=").toString());\r
-        Enumeration enumeration = permissions();\r
-        do {\r
-            if(!enumeration.hasMoreElements())\r
-                break;\r
-            Permission permission = (Permission)enumeration.nextElement();\r
-            stringbuffer.append(permission);\r
-            if(enumeration.hasMoreElements())\r
-                stringbuffer.append(",");\r
-        } while(true);\r
-        return new String(stringbuffer);\r
-    }\r
-\r
-    public synchronized Object clone() {\r
-        AclEntryImpl aclentryimpl = new AclEntryImpl(user);\r
-        aclentryimpl.permissionSet = (Vector)permissionSet.clone();\r
-        aclentryimpl.negative = negative;\r
-        return aclentryimpl;\r
-    }\r
-\r
-    public Principal getPrincipal() {\r
-        return user;\r
-    }\r
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEnumerator.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEnumerator.java
deleted file mode 100644 (file)
index df093cd..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.acl.Acl;\r
-import java.util.*;\r
-\r
-final class AclEnumerator implements Enumeration {\r
-    \r
-    Acl acl;\r
-    Enumeration u1;\r
-    Enumeration u2;\r
-    Enumeration g1;\r
-    Enumeration g2;\r
-\r
-    AclEnumerator(Acl acl1, Hashtable hashtable, Hashtable hashtable1, Hashtable hashtable2, Hashtable hashtable3) {\r
-        acl = acl1;\r
-        u1 = hashtable.elements();\r
-        u2 = hashtable2.elements();\r
-        g1 = hashtable1.elements();\r
-        g2 = hashtable3.elements();\r
-    }\r
-\r
-    public boolean hasMoreElements() {\r
-        return u1.hasMoreElements() || u2.hasMoreElements() || g1.hasMoreElements() || g2.hasMoreElements();\r
-    }\r
-\r
-    public Object nextElement() {\r
-        Acl acl1 = acl;\r
-        if(u2.hasMoreElements()) return u2.nextElement();\r
-        if(g1.hasMoreElements()) return g1.nextElement();\r
-        if(u1.hasMoreElements()) return u1.nextElement();\r
-        if(g2.hasMoreElements()) return g2.nextElement();\r
-        return acl1;\r
-    }\r
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclImpl.java
deleted file mode 100644 (file)
index 17c20f9..0000000
+++ /dev/null
@@ -1,211 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.Principal;\r
-import java.security.acl.*;\r
-import java.util.*;\r
-\r
-/**\r
- * Additional class for verification Acl interface \r
- */\r
-public class AclImpl extends OwnerImpl implements Acl {\r
-    \r
-    private Hashtable allowedUsersTable;\r
-    private Hashtable allowedGroupsTable;\r
-    private Hashtable deniedUsersTable;\r
-    private Hashtable deniedGroupsTable;\r
-    private String aclName;\r
-    private Vector zeroSet;\r
-\r
-    public AclImpl(Principal principal, String s) {\r
-        super(principal);\r
-        allowedUsersTable = new Hashtable(23);\r
-        allowedGroupsTable = new Hashtable(23);\r
-        deniedUsersTable = new Hashtable(23);\r
-        deniedGroupsTable = new Hashtable(23);\r
-        aclName = null;\r
-        zeroSet = new Vector(1, 1);\r
-        try {\r
-            setName(principal, s);\r
-        } catch(Exception exception) { }\r
-    }\r
-\r
-    public void setName(Principal principal, String s)\r
-                throws NotOwnerException {\r
-        if(!isOwner(principal)) {\r
-            throw new NotOwnerException();\r
-        } else {\r
-            aclName = s;\r
-            return;\r
-        }\r
-    }\r
-\r
-    public String getName() {\r
-        return aclName;\r
-    }\r
-\r
-    public synchronized boolean addEntry(Principal principal, AclEntry aclentry)\r
-                                throws NotOwnerException {\r
-        if(!isOwner(principal)) throw new NotOwnerException();\r
-        Hashtable hashtable = findTable(aclentry);\r
-        Principal principal1 = aclentry.getPrincipal();\r
-        if(hashtable.get(principal1) != null) {\r
-            return false;\r
-        } else {\r
-            hashtable.put(principal1, aclentry);\r
-            return true;\r
-        }\r
-    }\r
-\r
-    public synchronized boolean removeEntry(Principal principal, AclEntry aclentry)\r
-                                throws NotOwnerException {\r
-        if(!isOwner(principal)) {\r
-            throw new NotOwnerException();\r
-        } else {\r
-            Hashtable hashtable = findTable(aclentry);\r
-            Principal principal1 = aclentry.getPrincipal();\r
-            Object obj = hashtable.remove(principal1);\r
-            return obj != null;\r
-        }\r
-    }\r
-\r
-    public synchronized Enumeration getPermissions(Principal principal) {\r
-        Enumeration enumeration2 = subtract(getGroupPositive(principal), getGroupNegative(principal));\r
-        Enumeration enumeration3 = subtract(getGroupNegative(principal), getGroupPositive(principal));\r
-        Enumeration enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));\r
-        Enumeration enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));\r
-        Enumeration enumeration4 = subtract(enumeration2, enumeration1);\r
-        Enumeration enumeration5 = union(enumeration, enumeration4);\r
-        enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));\r
-        enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));\r
-        enumeration4 = subtract(enumeration3, enumeration);\r
-        Enumeration enumeration6 = union(enumeration1, enumeration4);\r
-        return subtract(enumeration5, enumeration6);\r
-    }\r
-\r
-    public boolean checkPermission(Principal principal, Permission permission) {\r
-        for(Enumeration enumeration = getPermissions(principal); enumeration.hasMoreElements();) {\r
-            Permission permission1 = (Permission)enumeration.nextElement();\r
-            if(permission1.equals(permission))\r
-                return true;\r
-        }\r
-        return false;\r
-    }\r
-\r
-    public synchronized Enumeration entries() {\r
-        return new AclEnumerator(this, allowedUsersTable, allowedGroupsTable, deniedUsersTable, deniedGroupsTable);\r
-    }\r
-\r
-    public String toString() {\r
-        StringBuffer stringbuffer = new StringBuffer();\r
-        for(Enumeration enumeration = entries(); enumeration.hasMoreElements(); stringbuffer.append("\n")) {\r
-            AclEntry aclentry = (AclEntry)enumeration.nextElement();\r
-            stringbuffer.append(aclentry.toString().trim());\r
-        }\r
-        return stringbuffer.toString();\r
-    }\r
-\r
-    private Hashtable findTable(AclEntry aclentry) {\r
-        Hashtable hashtable = null;\r
-        Principal principal = aclentry.getPrincipal();\r
-        if(principal instanceof Group) {\r
-            if(aclentry.isNegative())\r
-                hashtable = deniedGroupsTable;\r
-            else\r
-                hashtable = allowedGroupsTable;\r
-        } else\r
-        if(aclentry.isNegative())\r
-            hashtable = deniedUsersTable;\r
-        else\r
-            hashtable = allowedUsersTable;\r
-        return hashtable;\r
-    }\r
-\r
-    private static Enumeration union(Enumeration enumeration, Enumeration enumeration1) {\r
-        Vector vector = new Vector(20, 20);\r
-        for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));\r
-        do {\r
-            if(!enumeration1.hasMoreElements())\r
-                break;\r
-            Object obj = enumeration1.nextElement();\r
-            if(!vector.contains(obj))\r
-                vector.addElement(obj);\r
-        } while(true);\r
-        return vector.elements();\r
-    }\r
-\r
-    private Enumeration subtract(Enumeration enumeration, Enumeration enumeration1) {\r
-        Vector vector = new Vector(20, 20);\r
-        for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));\r
-        do {\r
-            if(!enumeration1.hasMoreElements())\r
-                break;\r
-            Object obj = enumeration1.nextElement();\r
-            if(vector.contains(obj))\r
-                vector.removeElement(obj);\r
-        } while(true);\r
-        return vector.elements();\r
-    }\r
-\r
-    private Enumeration getGroupPositive(Principal principal) {\r
-        Enumeration enumeration = zeroSet.elements();\r
-        Enumeration enumeration1 = allowedGroupsTable.keys();\r
-        do {\r
-            if(!enumeration1.hasMoreElements())\r
-                break;\r
-            Group group = (Group)enumeration1.nextElement();\r
-            if(group.isMember(principal)) {\r
-                AclEntry aclentry = (AclEntry)allowedGroupsTable.get(group);\r
-                enumeration = union(aclentry.permissions(), enumeration);\r
-            }\r
-        } while(true);\r
-        return enumeration;\r
-    }\r
-\r
-    private Enumeration getGroupNegative(Principal principal) {\r
-        Enumeration enumeration = zeroSet.elements();\r
-        Enumeration enumeration1 = deniedGroupsTable.keys();\r
-        do {\r
-            if(!enumeration1.hasMoreElements())\r
-                break;\r
-            Group group = (Group)enumeration1.nextElement();\r
-            if(group.isMember(principal)) {\r
-                AclEntry aclentry = (AclEntry)deniedGroupsTable.get(group);\r
-                enumeration = union(aclentry.permissions(), enumeration);\r
-            }\r
-        } while(true);\r
-        return enumeration;\r
-    }\r
-\r
-    private Enumeration getIndividualPositive(Principal principal) {\r
-        Enumeration enumeration = zeroSet.elements();\r
-        AclEntry aclentry = (AclEntry)allowedUsersTable.get(principal);\r
-        if(aclentry != null)\r
-            enumeration = aclentry.permissions();\r
-        return enumeration;\r
-    }\r
-\r
-    private Enumeration getIndividualNegative(Principal principal) {\r
-        Enumeration enumeration = zeroSet.elements();\r
-        AclEntry aclentry = (AclEntry)deniedUsersTable.get(principal);\r
-        if(aclentry != null)\r
-            enumeration = aclentry.permissions();\r
-        return enumeration;\r
-    }\r
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/GroupImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/GroupImpl.java
deleted file mode 100644 (file)
index fe910fb..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.Principal;\r
-import java.security.acl.Group;\r
-import java.util.Enumeration;\r
-import java.util.Vector;\r
-\r
-/**\r
- * Additional class for verification Group interface \r
- */\r
-public class GroupImpl implements Group {\r
-    \r
-    private Vector groupMembers;\r
-    private String group;\r
-\r
-    public GroupImpl(String s) {\r
-        groupMembers = new Vector(50, 100);\r
-        group = s;\r
-    }\r
-\r
-    public boolean addMember(Principal principal) {\r
-        if(groupMembers.contains(principal))\r
-            return false;\r
-        if(group.equals(principal.toString())) {\r
-            throw new IllegalArgumentException();\r
-        } else {\r
-            groupMembers.addElement(principal);\r
-            return true;\r
-        }\r
-    }\r
-\r
-    public boolean removeMember(Principal principal) {\r
-        return groupMembers.removeElement(principal);\r
-    }\r
-\r
-    public Enumeration members() {\r
-        return groupMembers.elements();\r
-    }\r
-\r
-    public boolean equals(Object obj) {\r
-        if(this == obj)\r
-            return true;\r
-        if(!(obj instanceof Group)) {\r
-            return false;\r
-        } else {\r
-            Group group1 = (Group)obj;\r
-            return group.equals(group1.toString());\r
-        }\r
-    }\r
-\r
-    public boolean equals(Group group1) {\r
-        return equals(group1);\r
-    }\r
-\r
-    public String toString() {\r
-        return group;\r
-    }\r
-\r
-    public int hashCode() {\r
-        return group.hashCode();\r
-    }\r
-\r
-    public boolean isMember(Principal principal) {\r
-        if(groupMembers.contains(principal)) {\r
-            return true;\r
-        } else {\r
-            Vector vector = new Vector(10);\r
-            return isMemberRecurse(principal, vector);\r
-        }\r
-    }\r
-\r
-    public String getName() {\r
-        return group;\r
-    }\r
-\r
-    boolean isMemberRecurse(Principal principal, Vector vector) {\r
-        for(Enumeration enumeration = members(); enumeration.hasMoreElements();) {\r
-            boolean flag = false;\r
-            Principal principal1 = (Principal)enumeration.nextElement();\r
-            if(principal1.equals(principal))\r
-                return true;\r
-            if(principal1 instanceof GroupImpl) {\r
-                GroupImpl groupimpl = (GroupImpl)principal1;\r
-                vector.addElement(this);\r
-                if(!vector.contains(groupimpl))\r
-                    flag = groupimpl.isMemberRecurse(principal, vector);\r
-            } else if(principal1 instanceof Group) {\r
-                Group group1 = (Group)principal1;\r
-                if(!vector.contains(group1)) flag = group1.isMember(principal);\r
-            } \r
-            if(flag) return flag;\r
-        }\r
-        return false;\r
-    }\r
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/OwnerImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/OwnerImpl.java
deleted file mode 100644 (file)
index c3012b6..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.Principal;\r
-import java.security.acl.*;\r
-import java.util.Enumeration;\r
-\r
-/**\r
- * Additional class for verification Owner interface \r
- */\r
-public class OwnerImpl implements Owner {\r
-    \r
-    private Group ownerGroup;\r
-    \r
-    public OwnerImpl(Principal principal) {\r
-        ownerGroup = new GroupImpl("AclOwners");\r
-        ownerGroup.addMember(principal);\r
-    }\r
-\r
-    public synchronized boolean addOwner(Principal principal, Principal principal1)\r
-                                throws NotOwnerException {\r
-        \r
-        if(!isOwner(principal))\r
-        {\r
-            throw new NotOwnerException();\r
-        } else {\r
-            if (ownerGroup.isMember(principal1)) return false;\r
-            if (!ownerGroup.isMember(principal1)) {\r
-                ownerGroup.addMember(principal1);\r
-                return true;\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-\r
-    public synchronized boolean deleteOwner(Principal principal, Principal principal1)\r
-                                throws NotOwnerException, LastOwnerException {\r
-        \r
-        if(!isOwner(principal)) throw new NotOwnerException();\r
-        Enumeration enumeration = ownerGroup.members();\r
-        Object obj = enumeration.nextElement();\r
-        if(enumeration.hasMoreElements()) {\r
-            return ownerGroup.removeMember(principal1);\r
-        } else {\r
-            throw new LastOwnerException();\r
-        }\r
-    }\r
-\r
-    public synchronized boolean isOwner(Principal principal)\r
-    {\r
-        return ownerGroup.isMember(principal);\r
-    }\r
-}\r
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PermissionImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PermissionImpl.java
deleted file mode 100644 (file)
index 2d355f9..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.acl.Permission;\r
-\r
-/**\r
- * Additional class for verification Permission interface \r
- */\r
-public class PermissionImpl implements Permission {\r
-    \r
-    private String permission;\r
-\r
-    public PermissionImpl(String s) {\r
-        permission = s;\r
-    }\r
-\r
-    public boolean equals(Object obj) {\r
-        if(obj instanceof Permission) {\r
-            Permission permission1 = (Permission)obj;\r
-            return permission.equals(permission1.toString());\r
-        } else {\r
-            return false;\r
-        }\r
-    }\r
-\r
-    public String toString() {\r
-        return permission;\r
-    }\r
-\r
-/*    public int hashCode() {\r
-        return toString().hashCode();\r
-    }*/\r
-}
\ No newline at end of file
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PrincipalImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PrincipalImpl.java
deleted file mode 100644 (file)
index f7dcba5..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.acl;\r
-\r
-import java.security.Principal;\r
-\r
-/**\r
- * Additional class for verification Principal interface \r
- */\r
-public class PrincipalImpl implements Principal {\r
-    \r
-    private String user;\r
-\r
-    public PrincipalImpl(String s) {\r
-        user = s;\r
-    }\r
-\r
-    public boolean equals(Object obj) {\r
-        if(obj instanceof PrincipalImpl) {\r
-            PrincipalImpl principalimpl = (PrincipalImpl)obj;\r
-            return user.equals(principalimpl.toString());\r
-        } else {\r
-            return false;\r
-        }\r
-    }\r
-\r
-    public String toString() {\r
-        return user;\r
-    }\r
-\r
-    public int hashCode() {\r
-        return user.hashCode();\r
-    }\r
-\r
-    public String getName() {\r
-        return user;\r
-    }\r
-}\r
diff --git a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/cert/PolicyNodeImpl.java b/libcore/support/src/test/java/org/apache/harmony/security/tests/support/cert/PolicyNodeImpl.java
deleted file mode 100644 (file)
index cfe2a43..0000000
+++ /dev/null
@@ -1,256 +0,0 @@
-/*\r
- *  Licensed to the Apache Software Foundation (ASF) under one or more\r
- *  contributor license agreements.  See the NOTICE file distributed with\r
- *  this work for additional information regarding copyright ownership.\r
- *  The ASF licenses this file to You under the Apache License, Version 2.0\r
- *  (the "License"); you may not use this file except in compliance with\r
- *  the License.  You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- */\r
-\r
-package org.apache.harmony.security.tests.support.cert;\r
-\r
-import java.security.cert.PolicyNode;\r
-import java.util.*;\r
-\r
-public class PolicyNodeImpl implements PolicyNode {\r
-    \r
-    private static final String ANY_POLICY = "2.5.29.32.0";\r
-    private PolicyNodeImpl mParent;\r
-    private HashSet mChildren;\r
-    private String mValidPolicy;\r
-    private HashSet mQualifierSet;\r
-    private boolean mCriticalityIndicator;\r
-    private HashSet mExpectedPolicySet;\r
-    private boolean mOriginalExpectedPolicySet;\r
-    private int mDepth;\r
-    private boolean isImmutable;\r
-\r
-    public PolicyNodeImpl(PolicyNodeImpl policynodeimpl, String s, Set set, \r
-                   boolean flag, Set set1, boolean flag1) {\r
-        isImmutable = false;\r
-        mParent = policynodeimpl;\r
-        mChildren = new HashSet();\r
-        if(s != null) {\r
-            mValidPolicy = s;\r
-        } else {\r
-            mValidPolicy = "";\r
-        }\r
-        if(set != null) {\r
-            mQualifierSet = new HashSet(set);\r
-        } else {\r
-            mQualifierSet = new HashSet();\r
-        }\r
-        mCriticalityIndicator = flag;\r
-        if(set1 != null) {\r
-            mExpectedPolicySet = new HashSet(set1);\r
-        } else {\r
-            mExpectedPolicySet = new HashSet();\r
-        }\r
-        mOriginalExpectedPolicySet = !flag1;\r
-        if(mParent != null) {\r
-            mDepth = mParent.getDepth() + 1;\r
-            mParent.addChild(this);\r
-        } else {\r
-            mDepth = 0;\r
-        }\r
-    }\r
-\r
-    PolicyNodeImpl(PolicyNodeImpl policynodeimpl, \r
-                   PolicyNodeImpl policynodeimpl1) {\r
-        this(policynodeimpl, policynodeimpl1.mValidPolicy, ((Set) (policynodeimpl1.mQualifierSet)), policynodeimpl1.mCriticalityIndicator, ((Set) (policynodeimpl1.mExpectedPolicySet)), false);\r
-    }\r
-\r
-    public PolicyNode getParent() {\r
-        return mParent;\r
-    }\r
-\r
-    public Iterator getChildren() {\r
-        return Collections.unmodifiableSet(mChildren).iterator();\r
-    }\r
-\r
-    public int getDepth() {\r
-        return mDepth;\r
-    }\r
-\r
-    public String getValidPolicy() {\r
-        return mValidPolicy;\r
-    }\r
-\r
-    public Set getPolicyQualifiers() {\r
-        return Collections.unmodifiableSet(mQualifierSet);\r
-    }\r
-\r
-    public Set getExpectedPolicies() {\r
-        return Collections.unmodifiableSet(mExpectedPolicySet);\r
-    }\r
-\r
-    public boolean isCritical() {\r
-        return mCriticalityIndicator;\r
-    }\r
-\r
-    public String toString() {\r
-        StringBuffer stringbuffer = new StringBuffer(asString());\r
-        for(Iterator iterator = getChildren(); iterator.hasNext(); stringbuffer.append((PolicyNodeImpl)iterator.next()));\r
-        return stringbuffer.toString();\r
-    }\r
-\r
-    boolean isImmutable() {\r
-        return isImmutable;\r
-    }\r
-\r
-    void setImmutable() {\r
-        if(isImmutable)  return;\r
-        PolicyNodeImpl policynodeimpl;\r
-        for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl.setImmutable())\r
-            policynodeimpl = (PolicyNodeImpl)iterator.next();\r
-\r
-        isImmutable = true;\r
-    }\r
-\r
-    private void addChild(PolicyNodeImpl policynodeimpl) {\r
-        if(isImmutable) {\r
-            throw new IllegalStateException("PolicyNode is immutable");\r
-        } else {\r
-            mChildren.add(policynodeimpl);\r
-            return;\r
-        }\r
-    }\r
-\r
-    void addExpectedPolicy(String s) {\r
-        if(isImmutable)\r
-            throw new IllegalStateException("PolicyNode is immutable");\r
-        if(mOriginalExpectedPolicySet) {\r
-            mExpectedPolicySet.clear();\r
-            mOriginalExpectedPolicySet = false;\r
-        }\r
-        mExpectedPolicySet.add(s);\r
-    }\r
-\r
-    void prune(int i) {\r
-        if(isImmutable)\r
-            throw new IllegalStateException("PolicyNode is immutable");\r
-        if(mChildren.size() == 0)\r
-            return;\r
-        Iterator iterator = mChildren.iterator();\r
-        do {\r
-            if(!iterator.hasNext())  break;\r
-            PolicyNodeImpl policynodeimpl = (PolicyNodeImpl)iterator.next();\r
-            policynodeimpl.prune(i);\r
-            if(policynodeimpl.mChildren.size() == 0 && i > mDepth + 1)\r
-                iterator.remove();\r
-        } while(true);\r
-    }\r
-\r
-    void deleteChild(PolicyNode policynode) {\r
-        if(isImmutable) {\r
-            throw new IllegalStateException("PolicyNode is immutable");\r
-        } else {\r
-            mChildren.remove(policynode);\r
-            return;\r
-        }\r
-    }\r
-\r
-    PolicyNodeImpl copyTree() {\r
-        return copyTree(null);\r
-    }\r
-\r
-    private PolicyNodeImpl copyTree(PolicyNodeImpl policynodeimpl) {\r
-        PolicyNodeImpl policynodeimpl1 = new PolicyNodeImpl(policynodeimpl, this);\r
-        PolicyNodeImpl policynodeimpl2;\r
-        for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl2.copyTree(policynodeimpl1))\r
-            policynodeimpl2 = (PolicyNodeImpl)iterator.next();\r
-\r
-        return policynodeimpl1;\r
-    }\r
-\r
-    Set getPolicyNodes(int i) {\r
-        HashSet hashset = new HashSet();\r
-        getPolicyNodes(i, ((Set) (hashset)));\r
-        return hashset;\r
-    }\r
-\r
-    private void getPolicyNodes(int i, Set set) {\r
-        if(mDepth == i) {\r
-            set.add(this);\r
-        } else {\r
-            PolicyNodeImpl policynodeimpl;\r
-            for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl.getPolicyNodes(i, set))\r
-                policynodeimpl = (PolicyNodeImpl)iterator.next();\r
-        }\r
-    }\r
-\r
-    Set getPolicyNodesExpected(int i, String s, boolean flag) {\r
-        if(s.equals("2.5.29.32.0"))\r
-            return getPolicyNodes(i);\r
-        else\r
-            return getPolicyNodesExpectedHelper(i, s, flag);\r
-    }\r
-\r
-    private Set getPolicyNodesExpectedHelper(int i, String s, boolean flag) {\r
-        HashSet hashset = new HashSet();\r
-        if(mDepth < i) {\r
-            PolicyNodeImpl policynodeimpl;\r
-            for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); hashset.addAll(policynodeimpl.getPolicyNodesExpectedHelper(i, s, flag)))\r
-                policynodeimpl = (PolicyNodeImpl)iterator.next();\r
-\r
-        } else if(flag) {\r
-            if(mExpectedPolicySet.contains("2.5.29.32.0"))\r
-                hashset.add(this);\r
-        } else if(mExpectedPolicySet.contains(s)) {\r
-            hashset.add(this);\r
-        }\r
-        return hashset;\r
-    }\r
-\r
-    Set getPolicyNodesValid(int i, String s) {\r
-        HashSet hashset = new HashSet();\r
-        if(mDepth < i) {\r
-            PolicyNodeImpl policynodeimpl;\r
-            for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); hashset.addAll(policynodeimpl.getPolicyNodesValid(i, s)))\r
-                policynodeimpl = (PolicyNodeImpl)iterator.next();\r
-\r
-        } else if(mValidPolicy.equals(s)) {\r
-            hashset.add(this);\r
-        }\r
-        return hashset;\r
-    }\r
-\r
-    private static String policyToString(String s) {\r
-        if(s.equals("2.5.29.32.0")) {\r
-            return "anyPolicy";\r
-        } else {\r
-            return s;\r
-        }\r
-    }\r
-\r
-    String asString() {\r
-        if(mParent == null)\r
-            return "anyPolicy  ROOT\n";\r
-        StringBuffer stringbuffer = new StringBuffer();\r
-        int i = 0;\r
-        for(int j = getDepth(); i < j; i++)\r
-            stringbuffer.append("  ");\r
-\r
-        stringbuffer.append(policyToString(getValidPolicy()));\r
-        stringbuffer.append("  CRIT: ");\r
-        stringbuffer.append(isCritical());\r
-        stringbuffer.append("  EP: ");\r
-        for(Iterator iterator = getExpectedPolicies().iterator(); iterator.hasNext(); stringbuffer.append(" ")) {\r
-            String s = (String)iterator.next();\r
-            stringbuffer.append(policyToString(s));\r
-        }\r
-\r
-        stringbuffer.append(" (");\r
-        stringbuffer.append(getDepth());\r
-        stringbuffer.append(")\n");\r
-        return stringbuffer.toString();\r
-    }\r
-}\r
index e949f1d..48c986c 100644 (file)
@@ -153,7 +153,7 @@ public class NumberFormatTest extends TestCase {
         Locale chLocale = new Locale("de", "CH");
         // END android-added
 
-        Locale[] requiredLocales = {usLocale, chLocale};
+        Locale[] requiredLocales = {usLocale, arLocale, chLocale};
         if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
             // locale dependent test, bug 1943269
             return;
index f8e8250..f501255 100644 (file)
@@ -324,10 +324,38 @@ static void enableDebugFeatures(u4 debugFlags)
 #endif
 }
 
-/* 
+/*
+ * Set Linux capability flags.
+ *
+ * Returns 0 on success, errno on failure.
+ */
+static int setCapabilities(int64_t permitted, int64_t effective)
+{
+#ifdef HAVE_ANDROID_OS
+    struct __user_cap_header_struct capheader;
+    struct __user_cap_data_struct capdata;
+
+    memset(&capheader, 0, sizeof(capheader));
+    memset(&capdata, 0, sizeof(capdata));
+
+    capheader.version = _LINUX_CAPABILITY_VERSION;
+    capheader.pid = 0;
+
+    capdata.effective = effective;
+    capdata.permitted = permitted;
+
+    LOGV("CAPSET perm=%llx eff=%llx\n", permitted, effective);
+    if (capset(&capheader, &capdata) != 0)
+        return errno;
+#endif /*HAVE_ANDROID_OS*/
+
+    return 0;
+}
+
+/*
  * Utility routine to fork zygote and specialize the child process.
  */
-static pid_t forkAndSpecializeCommon(const u4* args)
+static pid_t forkAndSpecializeCommon(const u4* args, bool isSystemServer)
 {
     pid_t pid;
 
@@ -336,6 +364,21 @@ static pid_t forkAndSpecializeCommon(const u4* args)
     ArrayObject* gids = (ArrayObject *)args[2];
     u4 debugFlags = args[3];
     ArrayObject *rlimits = (ArrayObject *)args[4];
+    int64_t permittedCapabilities, effectiveCapabilities;
+
+    if (isSystemServer) {
+        /*
+         * Don't use GET_ARG_LONG here for now.  gcc is generating code
+         * that uses register d8 as a temporary, and that's coming out
+         * scrambled in the child process.  b/3138621
+         */
+        //permittedCapabilities = GET_ARG_LONG(args, 5);
+        //effectiveCapabilities = GET_ARG_LONG(args, 7);
+        permittedCapabilities = args[5] | (int64_t) args[6] << 32;
+        effectiveCapabilities = args[7] | (int64_t) args[8] << 32;
+    } else {
+        permittedCapabilities = effectiveCapabilities = 0;
+    }
 
     if (!gDvm.zygote) {
         dvmThrowException("Ljava/lang/IllegalStateException;",
@@ -367,7 +410,8 @@ static pid_t forkAndSpecializeCommon(const u4* args)
             err = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
 
             if (err < 0) {
-                LOGW("cannot PR_SET_KEEPCAPS errno: %d", errno);
+                LOGE("cannot PR_SET_KEEPCAPS: %s", strerror(errno));
+                dvmAbort();
             }
         }
 
@@ -376,23 +420,34 @@ static pid_t forkAndSpecializeCommon(const u4* args)
         err = setgroupsIntarray(gids);
 
         if (err < 0) {
-            LOGW("cannot setgroups() errno: %d", errno);
+            LOGE("cannot setgroups(): %s", strerror(errno));
+            dvmAbort();
         }
 
         err = setrlimitsFromArray(rlimits);
 
         if (err < 0) {
-            LOGW("cannot setrlimit() errno: %d", errno);
+            LOGE("cannot setrlimit(): %s", strerror(errno));
+            dvmAbort();
         }
 
         err = setgid(gid);
         if (err < 0) {
-            LOGW("cannot setgid(%d) errno: %d", gid, errno);
+            LOGE("cannot setgid(%d): %s", gid, strerror(errno));
+            dvmAbort();
         }
 
         err = setuid(uid);
         if (err < 0) {
-            LOGW("cannot setuid(%d) errno: %d", uid, errno);
+            LOGE("cannot setuid(%d): %s", uid, strerror(errno));
+            dvmAbort();
+        }
+
+        err = setCapabilities(permittedCapabilities, effectiveCapabilities);
+        if (err != 0) {
+            LOGE("cannot set capabilities (%llx,%llx): %s\n",
+                permittedCapabilities, effectiveCapabilities, strerror(err));
+            dvmAbort();
         }
 
         /*
@@ -425,19 +480,20 @@ static void Dalvik_dalvik_system_Zygote_forkAndSpecialize(const u4* args,
 {
     pid_t pid;
 
-    pid = forkAndSpecializeCommon(args);
+    pid = forkAndSpecializeCommon(args, false);
 
     RETURN_INT(pid);
 }
 
-/* native public static int forkSystemServer(int uid, int gid, 
- *     int[] gids, int debugFlags); 
+/* native public static int forkSystemServer(int uid, int gid,
+ *     int[] gids, int debugFlags, long permittedCapabilities,
+ *     long effectiveCapabilities);
  */
 static void Dalvik_dalvik_system_Zygote_forkSystemServer(
         const u4* args, JValue* pResult)
 {
     pid_t pid;
-    pid = forkAndSpecializeCommon(args);
+    pid = forkAndSpecializeCommon(args, true);
 
     /* The zygote process checks whether the child process has died or not. */
     if (pid > 0) {
@@ -462,7 +518,7 @@ const DalvikNativeMethod dvm_dalvik_system_Zygote[] = {
         Dalvik_dalvik_system_Zygote_fork },
     { "forkAndSpecialize",            "(II[II[[I)I",
         Dalvik_dalvik_system_Zygote_forkAndSpecialize },
-    { "forkSystemServer",            "(II[II[[I)I",
+    { "forkSystemServer",            "(II[II[[IJJ)I",
         Dalvik_dalvik_system_Zygote_forkSystemServer },
     { NULL, NULL, NULL },
 };