Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: 提交

dalvik


Commit MetaInfo

修订版e831bf41aaf28d5abe8ced4218d36b84faa765d5 (tree)
时间2011-06-26 15:35:28
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Merge remote-tracking branch 'korg/froyo' into froyo-x86

更改概述

差异

--- a/libcore/concurrent/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
+++ b/libcore/concurrent/src/main/java/java/util/concurrent/CopyOnWriteArrayList.java
@@ -1,1317 +1,1184 @@
11 /*
2- * Written by Doug Lea with assistance from members of JCP JSR-166
3- * Expert Group. Adapted and released, under explicit permission,
4- * from JDK ArrayList.java which carries the following copyright:
5- *
6- * Copyright 1997 by Sun Microsystems, Inc.,
7- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
8- * All rights reserved.
9- *
10- * This software is the confidential and proprietary information
11- * of Sun Microsystems, Inc. ("Confidential Information"). You
12- * shall not disclose such Confidential Information and shall use
13- * it only in accordance with the terms of the license agreement
14- * you entered into with Sun.
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with this
4+ * work for additional information regarding copyright ownership. The ASF
5+ * licenses this file to you under the Apache License, Version 2.0 (the
6+ * "License"); you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+ * License for the specific language governing permissions and limitations under
15+ * the License.
1516 */
1617
1718 package java.util.concurrent;
18-import java.util.*;
19-import java.util.concurrent.locks.*;
20-import java.lang.reflect.Array;
21-
22-import sun.misc.Unsafe;
2319
24-// BEGIN android-note
25-// removed link to collections framework docs
26-// END android-note
20+import java.io.IOException;
21+import java.io.ObjectInputStream;
22+import java.io.ObjectOutputStream;
23+import java.io.Serializable;
24+import java.lang.reflect.Array;
25+import java.util.Collection;
26+import java.util.ConcurrentModificationException;
27+import java.util.Iterator;
28+import java.util.List;
29+import java.util.ListIterator;
30+import java.util.NoSuchElementException;
31+import java.util.RandomAccess;
32+import java.util.concurrent.locks.ReentrantLock;
2733
2834 /**
29- * A thread-safe variant of {@link java.util.ArrayList} in which all mutative
30- * operations (<tt>add</tt>, <tt>set</tt>, and so on) are implemented by
31- * making a fresh copy of the underlying array.
32- *
33- * <p> This is ordinarily too costly, but may be <em>more</em> efficient
34- * than alternatives when traversal operations vastly outnumber
35- * mutations, and is useful when you cannot or don't want to
36- * synchronize traversals, yet need to preclude interference among
37- * concurrent threads. The "snapshot" style iterator method uses a
38- * reference to the state of the array at the point that the iterator
39- * was created. This array never changes during the lifetime of the
40- * iterator, so interference is impossible and the iterator is
41- * guaranteed not to throw <tt>ConcurrentModificationException</tt>.
42- * The iterator will not reflect additions, removals, or changes to
43- * the list since the iterator was created. Element-changing
44- * operations on iterators themselves (<tt>remove</tt>, <tt>set</tt>, and
45- * <tt>add</tt>) are not supported. These methods throw
46- * <tt>UnsupportedOperationException</tt>.
47- *
48- * <p>All elements are permitted, including <tt>null</tt>.
49- *
50- * <p>Memory consistency effects: As with other concurrent
51- * collections, actions in a thread prior to placing an object into a
52- * {@code CopyOnWriteArrayList}
53- * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
54- * actions subsequent to the access or removal of that element from
55- * the {@code CopyOnWriteArrayList} in another thread.
35+ * Implements a {@link java.util.ArrayList} variant that is thread-safe. All
36+ * write operation result in a new copy of the underlying data being created.
37+ * Iterators reflect the state of the CopyOnWriteArrayList at the time they were
38+ * created. They are not updated to reflect subsequent changes to the list. In
39+ * addition, these iterators cannot be used for modifying the underlying
40+ * CopyOnWriteArrayList.
5641 *
57- * @since 1.5
58- * @author Doug Lea
59- * @param <E> the type of elements held in this collection
42+ * @param <E> the element type
6043 */
61-public class CopyOnWriteArrayList<E>
62- implements List<E>, RandomAccess, Cloneable, java.io.Serializable {
63- private static final long serialVersionUID = 8673264195747942595L;
64-
65- /** The lock protecting all mutators */
66- transient final ReentrantLock lock = new ReentrantLock();
44+public class CopyOnWriteArrayList<E> implements List<E>, RandomAccess, Cloneable, Serializable {
6745
68- /** The array, accessed only via getArray/setArray. */
69- private volatile transient Object[] array;
46+ private static final long serialVersionUID = 8673264195747942595L;
7047
71- /**
72- * Gets the array. Non-private so as to also be accessible
73- * from CopyOnWriteArraySet class.
74- */
75- final Object[] getArray() {
76- return array;
77- }
48+ private transient volatile E[] arr;
7849
7950 /**
80- * Sets the array.
51+ * Lock for the queue write methods
8152 */
82- final void setArray(Object[] a) {
83- array = a;
84- }
53+ private final transient ReentrantLock lock = new ReentrantLock();
8554
8655 /**
87- * Creates an empty list.
56+ * Creates a new, empty instance of CopyOnWriteArrayList.
8857 */
8958 public CopyOnWriteArrayList() {
90- setArray(new Object[0]);
9159 }
9260
9361 /**
94- * Creates a list containing the elements of the specified
95- * collection, in the order they are returned by the collection's
96- * iterator.
62+ * Creates a new instance of CopyOnWriteArrayList and fills it with the
63+ * contents of a given Collection.
9764 *
98- * @param c the collection of initially held elements
99- * @throws NullPointerException if the specified collection is null
65+ * @param c the collection the elements of which are to be copied into
66+ * the new instance.
10067 */
10168 public CopyOnWriteArrayList(Collection<? extends E> c) {
102- Object[] elements = c.toArray();
103- // c.toArray might (incorrectly) not return Object[] (see 6260652)
104- if (elements.getClass() != Object[].class)
105- elements = Java6Arrays.copyOf(elements, elements.length, Object[].class);
106- setArray(elements);
69+ this((E[]) c.toArray());
10770 }
10871
10972 /**
110- * Creates a list holding a copy of the given array.
73+ * Creates a new instance of CopyOnWriteArrayList and fills it with the
74+ * contents of a given array.
11175 *
112- * @param toCopyIn the array (a copy of this array is used as the
113- * internal array)
114- * @throws NullPointerException if the specified array is null
76+ * @param array the array the elements of which are to be copied into the
77+ * new instance.
11578 */
116- public CopyOnWriteArrayList(E[] toCopyIn) {
117- setArray(Java6Arrays.copyOf(toCopyIn, toCopyIn.length, Object[].class));
79+ public CopyOnWriteArrayList(E[] array) {
80+ int size = array.length;
81+ E[] data = newElementArray(size);
82+ for (int i = 0; i < size; i++) {
83+ data[i] = array[i];
84+ }
85+ arr = data;
11886 }
11987
120- /**
121- * Returns the number of elements in this list.
122- *
123- * @return the number of elements in this list
124- */
125- public int size() {
126- return getArray().length;
88+ public boolean add(E e) {
89+ lock.lock();
90+ try {
91+ E[] data;
92+ E[] old = getData();
93+ int size = old.length;
94+ data = newElementArray(size + 1);
95+ System.arraycopy(old, 0, data, 0, size);
96+ data[size] = e;
97+ setData(data);
98+ return true;
99+ } finally {
100+ lock.unlock();
101+ }
127102 }
128103
129- /**
130- * Returns <tt>true</tt> if this list contains no elements.
131- *
132- * @return <tt>true</tt> if this list contains no elements
133- */
134- public boolean isEmpty() {
135- return size() == 0;
104+ public void add(int index, E e) {
105+ lock.lock();
106+ try {
107+ E[] data;
108+ E[] old = getData();
109+ int size = old.length;
110+ checkIndexInclusive(index, size);
111+ data = newElementArray(size+1);
112+ System.arraycopy(old, 0, data, 0, index);
113+ data[index] = e;
114+ if (size > index) {
115+ System.arraycopy(old, index, data, index + 1, size - index);
116+ }
117+ setData(data);
118+ } finally {
119+ lock.unlock();
120+ }
136121 }
137122
138- /**
139- * Test for equality, coping with nulls.
140- */
141- private static boolean eq(Object o1, Object o2) {
142- return (o1 == null ? o2 == null : o1.equals(o2));
123+ public boolean addAll(Collection<? extends E> c) {
124+ Iterator it = c.iterator();
125+ int ssize = c.size();
126+ lock.lock();
127+ try {
128+ int size = size();
129+ E[] data;
130+ E[] old = getData();
131+ int nSize = size + ssize;
132+ data = newElementArray(nSize);
133+ System.arraycopy(old, 0, data, 0, size);
134+ while (it.hasNext()) {
135+ data[size++] = (E) it.next();
136+ }
137+ setData(data);
138+ } finally {
139+ lock.unlock();
140+ }
141+ return true;
143142 }
144143
145- /**
146- * static version of indexOf, to allow repeated calls without
147- * needing to re-acquire array each time.
148- * @param o element to search for
149- * @param elements the array
150- * @param index first index to search
151- * @param fence one past last index to search
152- * @return index of element, or -1 if absent
153- */
154- private static int indexOf(Object o, Object[] elements,
155- int index, int fence) {
156- if (o == null) {
157- for (int i = index; i < fence; i++)
158- if (elements[i] == null)
159- return i;
160- } else {
161- for (int i = index; i < fence; i++)
162- if (o.equals(elements[i]))
163- return i;
144+ public boolean addAll(int index, Collection<? extends E> c) {
145+ Iterator it = c.iterator();
146+ int ssize = c.size();
147+ lock.lock();
148+ try {
149+ int size = size();
150+ checkIndexInclusive(index, size);
151+ E[] data;
152+ E[] old = getData();
153+ int nSize = size + ssize;
154+ data = newElementArray(nSize);
155+ System.arraycopy(old, 0, data, 0, index);
156+ int i = index;
157+ while (it.hasNext()) {
158+ data[i++] = (E) it.next();
159+ }
160+ if (size > index) {
161+ System.arraycopy(old, index, data, index + ssize, size - index);
162+ }
163+ setData(data);
164+ } finally {
165+ lock.unlock();
164166 }
165- return -1;
167+ return true;
166168 }
167169
168170 /**
169- * static version of lastIndexOf.
170- * @param o element to search for
171- * @param elements the array
172- * @param index first index to search
173- * @return index of element, or -1 if absent
171+ * Adds to this CopyOnWriteArrayList all those elements from a given
172+ * collection that are not yet part of the list.
173+ *
174+ * @param c the collection from which the potential new elements are
175+ * taken.
176+ *
177+ * @return the number of elements actually added to this list.
174178 */
175- private static int lastIndexOf(Object o, Object[] elements, int index) {
176- if (o == null) {
177- for (int i = index; i >= 0; i--)
178- if (elements[i] == null)
179- return i;
180- } else {
181- for (int i = index; i >= 0; i--)
182- if (o.equals(elements[i]))
183- return i;
179+ public int addAllAbsent(Collection<? extends E> c) {
180+ if (c.size() == 0) {
181+ return 0;
182+ }
183+ lock.lock();
184+ try {
185+ E[] old = getData();
186+ int size = old.length;
187+ E[] toAdd = newElementArray(c.size());
188+ int i = 0;
189+ for (Iterator it = c.iterator(); it.hasNext();) {
190+ E o = (E) it.next();
191+ if (indexOf(o) < 0) {
192+ toAdd[i++] = o;
193+ }
194+ }
195+ E[] data = newElementArray(size + i);
196+ System.arraycopy(old, 0, data, 0, size);
197+ System.arraycopy(toAdd, 0, data, size, i);
198+ setData(data);
199+ return i;
200+ } finally {
201+ lock.unlock();
184202 }
185- return -1;
186203 }
187204
188205 /**
189- * Returns <tt>true</tt> if this list contains the specified element.
190- * More formally, returns <tt>true</tt> if and only if this list contains
191- * at least one element <tt>e</tt> such that
192- * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
206+ * Adds to this CopyOnWriteArrayList another element, given that this
207+ * element is not yet part of the list.
208+ *
209+ * @param e the potential new element.
193210 *
194- * @param o element whose presence in this list is to be tested
195- * @return <tt>true</tt> if this list contains the specified element
211+ * @return true if the element was added, or false otherwise.
196212 */
197- public boolean contains(Object o) {
198- Object[] elements = getArray();
199- return indexOf(o, elements, 0, elements.length) >= 0;
213+ public boolean addIfAbsent(E e) {
214+ lock.lock();
215+ try {
216+ E[] data;
217+ E[] old = getData();
218+ int size = old.length;
219+ if (size != 0) {
220+ if (indexOf(e) >= 0) {
221+ return false;
222+ }
223+ }
224+ data = newElementArray(size + 1);
225+ System.arraycopy(old, 0, data, 0, size);
226+ data[size] = e;
227+ setData(data);
228+ return true;
229+ } finally {
230+ lock.unlock();
231+ }
200232 }
201233
202- /**
203- * {@inheritDoc}
204- */
205- public int indexOf(Object o) {
206- Object[] elements = getArray();
207- return indexOf(o, elements, 0, elements.length);
234+ public void clear() {
235+ lock.lock();
236+ try {
237+ setData(newElementArray(0));
238+ } finally {
239+ lock.unlock();
240+ }
208241 }
209242
210- /**
211- * Returns the index of the first occurrence of the specified element in
212- * this list, searching forwards from <tt>index</tt>, or returns -1 if
213- * the element is not found.
214- * More formally, returns the lowest index <tt>i</tt> such that
215- * <tt>(i&nbsp;&gt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(e==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;e.equals(get(i))))</tt>,
216- * or -1 if there is no such index.
217- *
218- * @param e element to search for
219- * @param index index to start searching from
220- * @return the index of the first occurrence of the element in
221- * this list at position <tt>index</tt> or later in the list;
222- * <tt>-1</tt> if the element is not found.
223- * @throws IndexOutOfBoundsException if the specified index is negative
224- */
225- public int indexOf(E e, int index) {
226- Object[] elements = getArray();
227- return indexOf(e, elements, index, elements.length);
243+ @Override
244+ public Object clone() {
245+ try {
246+ CopyOnWriteArrayList thisClone = (CopyOnWriteArrayList) super.clone();
247+ thisClone.setData(this.getData());
248+ return thisClone;
249+ } catch (CloneNotSupportedException e) {
250+ throw new RuntimeException("CloneNotSupportedException is not expected here");
251+ }
228252 }
229253
230- /**
231- * {@inheritDoc}
232- */
233- public int lastIndexOf(Object o) {
234- Object[] elements = getArray();
235- return lastIndexOf(o, elements, elements.length - 1);
254+ public boolean contains(Object o) {
255+ return indexOf(o) >= 0;
236256 }
237257
238- /**
239- * Returns the index of the last occurrence of the specified element in
240- * this list, searching backwards from <tt>index</tt>, or returns -1 if
241- * the element is not found.
242- * More formally, returns the highest index <tt>i</tt> such that
243- * <tt>(i&nbsp;&lt;=&nbsp;index&nbsp;&amp;&amp;&nbsp;(e==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;e.equals(get(i))))</tt>,
244- * or -1 if there is no such index.
245- *
246- * @param e element to search for
247- * @param index index to start searching backwards from
248- * @return the index of the last occurrence of the element at position
249- * less than or equal to <tt>index</tt> in this list;
250- * -1 if the element is not found.
251- * @throws IndexOutOfBoundsException if the specified index is greater
252- * than or equal to the current size of this list
253- */
254- public int lastIndexOf(E e, int index) {
255- Object[] elements = getArray();
256- return lastIndexOf(e, elements, index);
258+ public boolean containsAll(Collection<?> c) {
259+ E[] data = getData();
260+ return containsAll(c, data, 0, data.length);
257261 }
258262
259- /**
260- * Returns a shallow copy of this list. (The elements themselves
261- * are not copied.)
262- *
263- * @return a clone of this list
264- */
265- public Object clone() {
266- try {
267- CopyOnWriteArrayList c = (CopyOnWriteArrayList)(super.clone());
268- c.resetLock();
269- return c;
270- } catch (CloneNotSupportedException e) {
271- // this shouldn't happen, since we are Cloneable
272- throw new InternalError();
263+ public boolean equals(Object o) {
264+ if (o == this) {
265+ return true;
266+ }
267+ if (!(o instanceof List)) {
268+ return false;
269+ }
270+ List l = (List) o;
271+ Iterator it = l.listIterator();
272+ Iterator ourIt = listIterator();
273+ while (it.hasNext()) {
274+ if (!ourIt.hasNext()) {
275+ return false;
276+ }
277+ Object thisListElem = it.next();
278+ Object anotherListElem = ourIt.next();
279+ if (!(thisListElem == null ? anotherListElem == null : thisListElem
280+ .equals(anotherListElem))) {
281+ return false;
282+ }
273283 }
284+ if (ourIt.hasNext()) {
285+ return false;
286+ }
287+ return true;
288+ }
289+
290+ public E get(int index) {
291+ E[] data = getData();
292+ return data[index];
293+ }
294+
295+ public int hashCode() {
296+ int hashCode = 1;
297+ Iterator it = listIterator();
298+ while (it.hasNext()) {
299+ Object obj = it.next();
300+ hashCode = 31 * hashCode + (obj == null ? 0 : obj.hashCode());
301+ }
302+ return hashCode;
274303 }
275304
276305 /**
277- * Returns an array containing all of the elements in this list
278- * in proper sequence (from first to last element).
306+ * Returns the index of a given element, starting the search from a given
307+ * position in the list.
279308 *
280- * <p>The returned array will be "safe" in that no references to it are
281- * maintained by this list. (In other words, this method must allocate
282- * a new array). The caller is thus free to modify the returned array.
309+ * @param e the element to search.
310+ * @param index the index at which to start the search.
283311 *
284- * <p>This method acts as bridge between array-based and collection-based
285- * APIs.
286- *
287- * @return an array containing all the elements in this list
312+ * @return the index of the element or null, if the element has not been
313+ * found at or beyond the given start index.
288314 */
289- public Object[] toArray() {
290- Object[] elements = getArray();
291- return Java6Arrays.copyOf(elements, elements.length);
315+ public int indexOf(E e, int index) {
316+ E[] data = getData();
317+ return indexOf(e, data, index, data.length - index);
318+ }
319+
320+ public int indexOf(Object o) {
321+ E[] data = getData();
322+ return indexOf(o, data, 0, data.length);
323+ }
324+
325+ public boolean isEmpty() {
326+ return size() == 0;
327+ }
328+
329+ public Iterator<E> iterator() {
330+ return new ListIteratorImpl(getData(), 0);
292331 }
293332
294333 /**
295- * Returns an array containing all of the elements in this list in
296- * proper sequence (from first to last element); the runtime type of
297- * the returned array is that of the specified array. If the list fits
298- * in the specified array, it is returned therein. Otherwise, a new
299- * array is allocated with the runtime type of the specified array and
300- * the size of this list.
301- *
302- * <p>If this list fits in the specified array with room to spare
303- * (i.e., the array has more elements than this list), the element in
304- * the array immediately following the end of the list is set to
305- * <tt>null</tt>. (This is useful in determining the length of this
306- * list <i>only</i> if the caller knows that this list does not contain
307- * any null elements.)
308- *
309- * <p>Like the {@link #toArray()} method, this method acts as bridge between
310- * array-based and collection-based APIs. Further, this method allows
311- * precise control over the runtime type of the output array, and may,
312- * under certain circumstances, be used to save allocation costs.
334+ * Returns the last index of a given element, starting the search from
335+ * a given position in the list and going backwards.
313336 *
314- * <p>Suppose <tt>x</tt> is a list known to contain only strings.
315- * The following code can be used to dump the list into a newly
316- * allocated array of <tt>String</tt>:
337+ * @param e the element to search.
338+ * @param index the index at which to start the search.
317339 *
318- * <pre>
319- * String[] y = x.toArray(new String[0]);</pre>
320- *
321- * Note that <tt>toArray(new Object[0])</tt> is identical in function to
322- * <tt>toArray()</tt>.
323- *
324- * @param a the array into which the elements of the list are to
325- * be stored, if it is big enough; otherwise, a new array of the
326- * same runtime type is allocated for this purpose.
327- * @return an array containing all the elements in this list
328- * @throws ArrayStoreException if the runtime type of the specified array
329- * is not a supertype of the runtime type of every element in
330- * this list
331- * @throws NullPointerException if the specified array is null
340+ * @return the index of the element or null, if the element has not been
341+ * found at or before the given start index.
332342 */
333- @SuppressWarnings("unchecked")
334- public <T> T[] toArray(T a[]) {
335- Object[] elements = getArray();
336- int len = elements.length;
337- if (a.length < len)
338- return (T[]) Java6Arrays.copyOf(elements, len, a.getClass());
339- else {
340- System.arraycopy(elements, 0, a, 0, len);
341- if (a.length > len)
342- a[len] = null;
343- return a;
344- }
343+ public int lastIndexOf(E e, int index) {
344+ E[] data = getData();
345+ return lastIndexOf(e, data, 0, index);
345346 }
346347
347- // Positional Access Operations
348+ public int lastIndexOf(Object o) {
349+ E[] data = getData();
350+ return lastIndexOf(o, data, 0, data.length);
351+ }
348352
349- @SuppressWarnings("unchecked")
350- private E get(Object[] a, int index) {
351- return (E) a[index];
353+ public ListIterator<E> listIterator() {
354+ return new ListIteratorImpl(getData(), 0);
352355 }
353356
354- /**
355- * {@inheritDoc}
356- *
357- * @throws IndexOutOfBoundsException {@inheritDoc}
358- */
359- public E get(int index) {
360- return get(getArray(), index);
357+ public ListIterator<E> listIterator(int index) {
358+ E[] data = getData();
359+ checkIndexInclusive(index, data.length);
360+ return new ListIteratorImpl(data, index);
361361 }
362362
363- /**
364- * Replaces the element at the specified position in this list with the
365- * specified element.
366- *
367- * @throws IndexOutOfBoundsException {@inheritDoc}
368- */
369- public E set(int index, E element) {
370- final ReentrantLock lock = this.lock;
363+ public E remove(int index) {
364+ return removeRange(index, 1);
365+ }
366+
367+ public boolean remove(Object o) {
371368 lock.lock();
372369 try {
373- Object[] elements = getArray();
374- E oldValue = get(elements, index);
375-
376- if (oldValue != element) {
377- int len = elements.length;
378- Object[] newElements = Java6Arrays.copyOf(elements, len);
379- newElements[index] = element;
380- setArray(newElements);
381- } else {
382- // Not quite a no-op; ensures volatile write semantics
383- setArray(elements);
370+ int index = indexOf(o);
371+ if (index == -1) {
372+ return false;
384373 }
385- return oldValue;
374+ remove(index);
375+ return true;
386376 } finally {
387377 lock.unlock();
388378 }
389379 }
390380
391- /**
392- * Appends the specified element to the end of this list.
393- *
394- * @param e element to be appended to this list
395- * @return <tt>true</tt> (as specified by {@link Collection#add})
396- */
397- public boolean add(E e) {
398- final ReentrantLock lock = this.lock;
381+ public boolean removeAll(Collection<?> c) {
399382 lock.lock();
400383 try {
401- Object[] elements = getArray();
402- int len = elements.length;
403- Object[] newElements = Java6Arrays.copyOf(elements, len + 1);
404- newElements[len] = e;
405- setArray(newElements);
406- return true;
384+ return removeAll(c, 0, getData().length) != 0;
407385 } finally {
408386 lock.unlock();
409387 }
410388 }
411389
412- /**
413- * Inserts the specified element at the specified position in this
414- * list. Shifts the element currently at that position (if any) and
415- * any subsequent elements to the right (adds one to their indices).
416- *
417- * @throws IndexOutOfBoundsException {@inheritDoc}
418- */
419- public void add(int index, E element) {
420- final ReentrantLock lock = this.lock;
390+ public boolean retainAll(Collection<?> c) {
391+ if (c == null) {
392+ throw new NullPointerException();
393+ }
421394 lock.lock();
422395 try {
423- Object[] elements = getArray();
424- int len = elements.length;
425- if (index > len || index < 0)
426- throw new IndexOutOfBoundsException("Index: "+index+
427- ", Size: "+len);
428- Object[] newElements;
429- int numMoved = len - index;
430- if (numMoved == 0)
431- newElements = Java6Arrays.copyOf(elements, len + 1);
432- else {
433- newElements = new Object[len + 1];
434- System.arraycopy(elements, 0, newElements, 0, index);
435- System.arraycopy(elements, index, newElements, index + 1,
436- numMoved);
437- }
438- newElements[index] = element;
439- setArray(newElements);
396+ return retainAll(c, 0, getData().length) != 0;
440397 } finally {
441398 lock.unlock();
442399 }
443400 }
444401
445- /**
446- * Removes the element at the specified position in this list.
447- * Shifts any subsequent elements to the left (subtracts one from their
448- * indices). Returns the element that was removed from the list.
449- *
450- * @throws IndexOutOfBoundsException {@inheritDoc}
451- */
452- public E remove(int index) {
453- final ReentrantLock lock = this.lock;
402+ public E set(int index, E e) {
454403 lock.lock();
455404 try {
456- Object[] elements = getArray();
457- int len = elements.length;
458- E oldValue = get(elements, index);
459- int numMoved = len - index - 1;
460- if (numMoved == 0)
461- setArray(Java6Arrays.copyOf(elements, len - 1));
462- else {
463- Object[] newElements = new Object[len - 1];
464- System.arraycopy(elements, 0, newElements, 0, index);
465- System.arraycopy(elements, index + 1, newElements, index,
466- numMoved);
467- setArray(newElements);
468- }
469- return oldValue;
405+ int size = size();
406+ checkIndexExlusive(index, size);
407+ E[] data;
408+ data = newElementArray(size);
409+ E[] oldArr = getData();
410+ System.arraycopy(oldArr, 0, data, 0, size);
411+ E old = data[index];
412+ data[index] = e;
413+ setData(data);
414+ return old;
470415 } finally {
471416 lock.unlock();
472417 }
473418 }
474419
475- /**
476- * Removes the first occurrence of the specified element from this list,
477- * if it is present. If this list does not contain the element, it is
478- * unchanged. More formally, removes the element with the lowest index
479- * <tt>i</tt> such that
480- * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
481- * (if such an element exists). Returns <tt>true</tt> if this list
482- * contained the specified element (or equivalently, if this list
483- * changed as a result of the call).
484- *
485- * @param o element to be removed from this list, if present
486- * @return <tt>true</tt> if this list contained the specified element
487- */
488- public boolean remove(Object o) {
489- final ReentrantLock lock = this.lock;
490- lock.lock();
491- try {
492- Object[] elements = getArray();
493- int len = elements.length;
494- if (len != 0) {
495- // Copy while searching for element to remove
496- // This wins in the normal case of element being present
497- int newlen = len - 1;
498- Object[] newElements = new Object[newlen];
499-
500- for (int i = 0; i < newlen; ++i) {
501- if (eq(o, elements[i])) {
502- // found one; copy remaining and exit
503- for (int k = i + 1; k < len; ++k)
504- newElements[k-1] = elements[k];
505- setArray(newElements);
506- return true;
507- } else
508- newElements[i] = elements[i];
509- }
420+ public int size() {
421+ return getData().length;
422+ }
510423
511- // special handling for last cell
512- if (eq(o, elements[newlen])) {
513- setArray(newElements);
514- return true;
515- }
516- }
517- return false;
518- } finally {
519- lock.unlock();
520- }
424+ public List<E> subList(int fromIndex, int toIndex) {
425+ return new SubList(this, fromIndex, toIndex);
521426 }
522427
523- /**
524- * Removes from this list all of the elements whose index is between
525- * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
526- * Shifts any succeeding elements to the left (reduces their index).
527- * This call shortens the list by <tt>(toIndex - fromIndex)</tt> elements.
528- * (If <tt>toIndex==fromIndex</tt>, this operation has no effect.)
529- *
530- * @param fromIndex index of first element to be removed
531- * @param toIndex index after last element to be removed
532- * @throws IndexOutOfBoundsException if fromIndex or toIndex out of range
533- * (@code{fromIndex < 0 || toIndex > size() || toIndex < fromIndex})
534- */
535- private void removeRange(int fromIndex, int toIndex) {
536- final ReentrantLock lock = this.lock;
537- lock.lock();
538- try {
539- Object[] elements = getArray();
540- int len = elements.length;
541-
542- if (fromIndex < 0 || toIndex > len || toIndex < fromIndex)
543- throw new IndexOutOfBoundsException();
544- int newlen = len - (toIndex - fromIndex);
545- int numMoved = len - toIndex;
546- if (numMoved == 0)
547- setArray(Java6Arrays.copyOf(elements, newlen));
548- else {
549- Object[] newElements = new Object[newlen];
550- System.arraycopy(elements, 0, newElements, 0, fromIndex);
551- System.arraycopy(elements, toIndex, newElements,
552- fromIndex, numMoved);
553- setArray(newElements);
554- }
555- } finally {
556- lock.unlock();
557- }
428+ public Object[] toArray() {
429+ E[] data = getData();
430+ return toArray(data, 0, data.length);
558431 }
559432
560- /**
561- * Append the element if not present.
562- *
563- * @param e element to be added to this list, if absent
564- * @return <tt>true</tt> if the element was added
565- */
566- public boolean addIfAbsent(E e) {
567- final ReentrantLock lock = this.lock;
568- lock.lock();
569- try {
570- // Copy while checking if already present.
571- // This wins in the most common case where it is not present
572- Object[] elements = getArray();
573- int len = elements.length;
574- Object[] newElements = new Object[len + 1];
575- for (int i = 0; i < len; ++i) {
576- if (eq(e, elements[i]))
577- return false; // exit, throwing away copy
578- else
579- newElements[i] = elements[i];
580- }
581- newElements[len] = e;
582- setArray(newElements);
583- return true;
584- } finally {
585- lock.unlock();
433+ public <T> T[] toArray(T[] a) {
434+ E[] data = getData();
435+ return (T[]) toArray(a, data, 0, data.length);
436+ }
437+
438+ @Override
439+ public String toString() {
440+ StringBuilder sb = new StringBuilder("[");
441+
442+ Iterator it = listIterator();
443+ while (it.hasNext()) {
444+ sb.append(String.valueOf(it.next()));
445+ sb.append(", ");
586446 }
447+ if (sb.length() > 1) {
448+ sb.setLength(sb.length() - 2);
449+ }
450+ sb.append("]");
451+ return sb.toString();
452+ }
453+
454+ // private and package private methods
455+
456+ @SuppressWarnings("unchecked")
457+ private final E[] newElementArray(int size) {
458+ return (E[])new Object[size];
587459 }
588460
589461 /**
590- * Returns <tt>true</tt> if this list contains all of the elements of the
591- * specified collection.
462+ * sets the internal data array
592463 *
593- * @param c collection to be checked for containment in this list
594- * @return <tt>true</tt> if this list contains all of the elements of the
595- * specified collection
596- * @throws NullPointerException if the specified collection is null
597- * @see #contains(Object)
464+ * @param data array to set
598465 */
599- public boolean containsAll(Collection<?> c) {
600- Object[] elements = getArray();
601- int len = elements.length;
602- for (Object e : c) {
603- if (indexOf(e, elements, 0, len) < 0)
604- return false;
605- }
606- return true;
466+ private final void setData(E[] data) {
467+ arr = data;
607468 }
608469
609470 /**
610- * Removes from this list all of its elements that are contained in
611- * the specified collection. This is a particularly expensive operation
612- * in this class because of the need for an internal temporary array.
471+ * gets the internal data array (or a new array if it is null)
613472 *
614- * @param c collection containing elements to be removed from this list
615- * @return <tt>true</tt> if this list changed as a result of the call
616- * @throws ClassCastException if the class of an element of this list
617- * is incompatible with the specified collection (optional)
618- * @throws NullPointerException if this list contains a null element and the
619- * specified collection does not permit null elements (optional),
620- * or if the specified collection is null
621- * @see #remove(Object)
473+ * @return the data array
622474 */
623- public boolean removeAll(Collection<?> c) {
624- final ReentrantLock lock = this.lock;
625- lock.lock();
626- try {
627- Object[] elements = getArray();
628- int len = elements.length;
629- if (len != 0) {
630- // temp array holds those elements we know we want to keep
631- int newlen = 0;
632- Object[] temp = new Object[len];
633- for (int i = 0; i < len; ++i) {
634- Object element = elements[i];
635- if (!c.contains(element))
636- temp[newlen++] = element;
637- }
638- if (newlen != len) {
639- setArray(Java6Arrays.copyOf(temp, newlen));
640- return true;
641- }
642- }
643- return false;
644- } finally {
645- lock.unlock();
475+ final E[] getData() {
476+ if (arr == null) {
477+ return newElementArray(0);
646478 }
479+ return arr;
647480 }
648481
649482 /**
650- * Retains only the elements in this list that are contained in the
651- * specified collection. In other words, removes from this list all of
652- * its elements that are not contained in the specified collection.
483+ * Removes from the specified range of this list
484+ * all the elements that are contained in the specified collection
485+ * <p/>
486+ * !should be called under lock
653487 *
654- * @param c collection containing elements to be retained in this list
655- * @return <tt>true</tt> if this list changed as a result of the call
656- * @throws ClassCastException if the class of an element of this list
657- * is incompatible with the specified collection (optional)
658- * @throws NullPointerException if this list contains a null element and the
659- * specified collection does not permit null elements (optional),
660- * or if the specified collection is null
661- * @see #remove(Object)
488+ * @return Returns the number of removed elements
662489 */
663- public boolean retainAll(Collection<?> c) {
664- final ReentrantLock lock = this.lock;
665- lock.lock();
666- try {
667- Object[] elements = getArray();
668- int len = elements.length;
669- if (len != 0) {
670- // temp array holds those elements we know we want to keep
671- int newlen = 0;
672- Object[] temp = new Object[len];
673- for (int i = 0; i < len; ++i) {
674- Object element = elements[i];
675- if (c.contains(element))
676- temp[newlen++] = element;
677- }
678- if (newlen != len) {
679- setArray(Java6Arrays.copyOf(temp, newlen));
680- return true;
681- }
490+ final int removeAll(Collection c, int start, int size) {
491+ int ssize = c.size();
492+ if (ssize == 0) {
493+ return 0;
494+ }
495+ Object[] old = getData();
496+ int arrsize = old.length;
497+ if (arrsize == 0) {
498+ return 0;
499+ }
500+ Object[] data = new Object[size];
501+ int j = 0;
502+ for (int i = start; i < (start + size); i++) {
503+ if (!c.contains(old[i])) {
504+ data[j++] = old[i];
682505 }
683- return false;
684- } finally {
685- lock.unlock();
686506 }
507+ if (j != size) {
508+ E[] result = newElementArray(arrsize - (size - j));
509+ System.arraycopy(old, 0, result, 0, start);
510+ System.arraycopy(data, 0, result, start, j);
511+ System.arraycopy(old, start + size, result, start + j, arrsize
512+ - (start + size));
513+ setData(result);
514+ return (size - j);
515+ }
516+ return 0;
687517 }
688518
689519 /**
690- * Appends all of the elements in the specified collection that
691- * are not already contained in this list, to the end of
692- * this list, in the order that they are returned by the
693- * specified collection's iterator.
520+ * Retains only the elements in the specified range of this list
521+ * that are contained in the specified collection
694522 *
695- * @param c collection containing elements to be added to this list
696- * @return the number of elements added
697- * @throws NullPointerException if the specified collection is null
698- * @see #addIfAbsent(Object)
523+ * @return Returns the number of removed elements
699524 */
700- public int addAllAbsent(Collection<? extends E> c) {
701- Object[] cs = c.toArray();
702- if (cs.length == 0)
525+ // should be called under lock
526+ int retainAll(Collection c, int start, int size) {
527+ Object[] old = getData();
528+ if (size == 0) {
703529 return 0;
704- Object[] uniq = new Object[cs.length];
705- final ReentrantLock lock = this.lock;
706- lock.lock();
707- try {
708- Object[] elements = getArray();
709- int len = elements.length;
710- int added = 0;
711- for (int i = 0; i < cs.length; ++i) { // scan for duplicates
712- Object e = cs[i];
713- if (indexOf(e, elements, 0, len) < 0 &&
714- indexOf(e, uniq, 0, added) < 0)
715- uniq[added++] = e;
530+ }
531+ if (c.size() == 0) {
532+ E[] data;
533+ if (size == old.length) {
534+ data = newElementArray(0);
535+ } else {
536+ data = newElementArray(old.length - size);
537+ System.arraycopy(old, 0, data, 0, start);
538+ System.arraycopy(old, start + size, data, start, old.length
539+ - start - size);
716540 }
717- if (added > 0) {
718- Object[] newElements = Java6Arrays.copyOf(elements, len + added);
719- System.arraycopy(uniq, 0, newElements, len, added);
720- setArray(newElements);
541+ setData(data);
542+ return size;
543+ }
544+ Object[] temp = new Object[size];
545+ int pos = 0;
546+ for (int i = start; i < (start + size); i++) {
547+ if (c.contains(old[i])) {
548+ temp[pos++] = old[i];
721549 }
722- return added;
723- } finally {
724- lock.unlock();
725550 }
551+ if (pos == size) {
552+ return 0;
553+ }
554+ E[] data = newElementArray(pos + old.length - size);
555+ System.arraycopy(old, 0, data, 0, start);
556+ System.arraycopy(temp, 0, data, start, pos);
557+ System.arraycopy(old, start + size, data, start + pos, old.length
558+ - start - size);
559+ setData(data);
560+ return (size - pos);
726561 }
727562
728563 /**
729- * Removes all of the elements from this list.
730- * The list will be empty after this call returns.
564+ * Removes specified range from this list
731565 */
732- public void clear() {
733- final ReentrantLock lock = this.lock;
566+ E removeRange(int start, int size) {
734567 lock.lock();
735568 try {
736- setArray(new Object[0]);
569+ int sizeArr = size();
570+ checkIndexExlusive(start, sizeArr);
571+ checkIndexInclusive(start + size, sizeArr);
572+ E[] data;
573+ data = newElementArray(sizeArr - size);
574+ E[] oldArr = getData();
575+ System.arraycopy(oldArr, 0, data, 0, start);
576+ E old = oldArr[start];
577+ if (sizeArr > (start + size)) {
578+ System.arraycopy(oldArr, start + size, data, start, sizeArr
579+ - (start + size));
580+ }
581+ setData(data);
582+ return old;
737583 } finally {
738584 lock.unlock();
739585 }
740586 }
741587
588+ // some util static functions to use by iterators and methods
742589 /**
743- * Appends all of the elements in the specified collection to the end
744- * of this list, in the order that they are returned by the specified
745- * collection's iterator.
746- *
747- * @param c collection containing elements to be added to this list
748- * @return <tt>true</tt> if this list changed as a result of the call
749- * @throws NullPointerException if the specified collection is null
750- * @see #add(Object)
590+ * Returns an array containing all of the elements
591+ * in the specified range of the array in proper sequence
751592 */
752- public boolean addAll(Collection<? extends E> c) {
753- Object[] cs = c.toArray();
754- if (cs.length == 0)
755- return false;
756- final ReentrantLock lock = this.lock;
757- lock.lock();
758- try {
759- Object[] elements = getArray();
760- int len = elements.length;
761- Object[] newElements = Java6Arrays.copyOf(elements, len + cs.length);
762- System.arraycopy(cs, 0, newElements, len, cs.length);
763- setArray(newElements);
764- return true;
765- } finally {
766- lock.unlock();
767- }
593+ static Object[] toArray(Object[] data, int start, int size) {
594+ Object[] result = new Object[size];
595+ System.arraycopy(data, start, result, 0, size);
596+ return result;
768597 }
769598
770599 /**
771- * Inserts all of the elements in the specified collection into this
772- * list, starting at the specified position. Shifts the element
773- * currently at that position (if any) and any subsequent elements to
774- * the right (increases their indices). The new elements will appear
775- * in this list in the order that they are returned by the
776- * specified collection's iterator.
777- *
778- * @param index index at which to insert the first element
779- * from the specified collection
780- * @param c collection containing elements to be added to this list
781- * @return <tt>true</tt> if this list changed as a result of the call
782- * @throws IndexOutOfBoundsException {@inheritDoc}
783- * @throws NullPointerException if the specified collection is null
784- * @see #add(int,Object)
600+ * Returns an array containing all of the elements
601+ * in the specified range of the array in proper sequence,
602+ * stores the result in the array, specified by first parameter
603+ * (as for public instance method toArray(Object[] to)
785604 */
786- public boolean addAll(int index, Collection<? extends E> c) {
787- Object[] cs = c.toArray();
788- final ReentrantLock lock = this.lock;
789- lock.lock();
790- try {
791- Object[] elements = getArray();
792- int len = elements.length;
793- if (index > len || index < 0)
794- throw new IndexOutOfBoundsException("Index: "+index+
795- ", Size: "+len);
796- if (cs.length == 0)
797- return false;
798- int numMoved = len - index;
799- Object[] newElements;
800- if (numMoved == 0)
801- newElements = Java6Arrays.copyOf(elements, len + cs.length);
802- else {
803- newElements = new Object[len + cs.length];
804- System.arraycopy(elements, 0, newElements, 0, index);
805- System.arraycopy(elements, index,
806- newElements, index + cs.length,
807- numMoved);
605+ static Object[] toArray(Object[] to, Object[] data, int start, int size) {
606+ int l = data.length;
607+ if (to.length < l) {
608+ to = (Object[]) Array.newInstance(to.getClass().getComponentType(),
609+ l);
610+ } else {
611+ if (to.length > l) {
612+ to[l] = null;
808613 }
809- System.arraycopy(cs, 0, newElements, index, cs.length);
810- setArray(newElements);
811- return true;
812- } finally {
813- lock.unlock();
814614 }
615+ System.arraycopy(data, start, to, 0, size);
616+ return to;
815617 }
816618
817619 /**
818- * Save the state of the list to a stream (i.e., serialize it).
620+ * Checks if the specified range of the
621+ * array contains all of the elements in the collection
819622 *
820- * @serialData The length of the array backing the list is emitted
821- * (int), followed by all of its elements (each an Object)
822- * in the proper order.
823- * @param s the stream
623+ * @param c collection with elements
624+ * @param data array where to search the elements
625+ * @param start start index
626+ * @param size size of the range
824627 */
825- private void writeObject(java.io.ObjectOutputStream s)
826- throws java.io.IOException{
827-
828- // Write out element count, and any hidden stuff
829- s.defaultWriteObject();
830-
831- Object[] elements = getArray();
832- int len = elements.length;
833- // Write out array length
834- s.writeInt(len);
835-
836- // Write out all elements in the proper order.
837- for (int i = 0; i < len; i++)
838- s.writeObject(elements[i]);
839- }
840-
841- /**
842- * Reconstitute the list from a stream (i.e., deserialize it).
843- * @param s the stream
844- */
845- private void readObject(java.io.ObjectInputStream s)
846- throws java.io.IOException, ClassNotFoundException {
847-
848- // Read in size, and any hidden stuff
849- s.defaultReadObject();
850-
851- // bind to new lock
852- resetLock();
853-
854- // Read in array length and allocate array
855- int len = s.readInt();
856- Object[] elements = new Object[len];
857-
858- // Read in all elements in the proper order.
859- for (int i = 0; i < len; i++)
860- elements[i] = s.readObject();
861- setArray(elements);
628+ static final boolean containsAll(Collection c, Object[] data, int start,
629+ int size) {
630+ if (size == 0) {
631+ return false;
632+ }
633+ Iterator it = c.iterator();
634+ while (it.hasNext()) {
635+ Object next = it.next();
636+ if (indexOf(next, data, start, size) < 0) {
637+ return false;
638+ }
639+ }
640+ return true;
862641 }
863642
864643 /**
865- * Returns a string representation of this list. The string
866- * representation consists of the string representations of the list's
867- * elements in the order they are returned by its iterator, enclosed in
868- * square brackets (<tt>"[]"</tt>). Adjacent elements are separated by
869- * the characters <tt>", "</tt> (comma and space). Elements are
870- * converted to strings as by {@link String#valueOf(Object)}.
644+ * Returns the index in the specified range of the data array
645+ * of the last occurrence of the specified element
871646 *
872- * @return a string representation of this list
647+ * @param o element to search
648+ * @param data array where to search
649+ * @param start start index
650+ * @param size size of the range
651+ * @return
873652 */
874- public String toString() {
875- return Arrays.toString(getArray());
653+ static final int lastIndexOf(Object o, Object[] data, int start, int size) {
654+ if (size == 0) {
655+ return -1;
656+ }
657+ if (o != null) {
658+ for (int i = start + size - 1; i > start - 1; i--) {
659+ if (o.equals(data[i])) {
660+ return i;
661+ }
662+ }
663+ } else {
664+ for (int i = start + size - 1; i > start - 1; i--) {
665+ if (data[i] == null) {
666+ return i;
667+ }
668+ }
669+ }
670+ return -1;
876671 }
877672
878673 /**
879- * Compares the specified object with this list for equality.
880- * Returns {@code true} if the specified object is the same object
881- * as this object, or if it is also a {@link List} and the sequence
882- * of elements returned by an {@linkplain List#iterator() iterator}
883- * over the specified list is the same as the sequence returned by
884- * an iterator over this list. The two sequences are considered to
885- * be the same if they have the same length and corresponding
886- * elements at the same position in the sequence are <em>equal</em>.
887- * Two elements {@code e1} and {@code e2} are considered
888- * <em>equal</em> if {@code (e1==null ? e2==null : e1.equals(e2))}.
674+ * Returns the index in the specified range of the data array
675+ * of the first occurrence of the specified element
889676 *
890- * @param o the object to be compared for equality with this list
891- * @return {@code true} if the specified object is equal to this list
677+ * @param o element to search
678+ * @param data array where to search
679+ * @param start start index
680+ * @param size end index
681+ * @return
892682 */
893- public boolean equals(Object o) {
894- if (o == this)
895- return true;
896- if (!(o instanceof List))
897- return false;
898-
899- List<?> list = (List<?>)(o);
900- Iterator<?> it = list.iterator();
901- Object[] elements = getArray();
902- int len = elements.length;
903- for (int i = 0; i < len; ++i)
904- if (!it.hasNext() || !eq(elements[i], it.next()))
905- return false;
906- if (it.hasNext())
907- return false;
908- return true;
683+ static final int indexOf(Object o, Object[] data, int start, int size) {
684+ if (size == 0) {
685+ return -1;
686+ }
687+ if (o == null) {
688+ for (int i = start; i < start + size; i++) {
689+ if (data[i] == null) {
690+ return i;
691+ }
692+ }
693+ } else {
694+ for (int i = start; i < start + size; i++) {
695+ if (o.equals(data[i])) {
696+ return i;
697+ }
698+ }
699+ }
700+ return -1;
909701 }
910702
911703 /**
912- * Returns the hash code value for this list.
913- *
914- * <p>This implementation uses the definition in {@link List#hashCode}.
704+ * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
705+ * is out of the list bounds.
915706 *
916- * @return the hash code value for this list
707+ * @param index element index to check.
917708 */
918- public int hashCode() {
919- int hashCode = 1;
920- Object[] elements = getArray();
921- int len = elements.length;
922- for (int i = 0; i < len; ++i) {
923- Object obj = elements[i];
924- hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
709+ static final void checkIndexInclusive(int index, int size) {
710+ if (index < 0 || index > size) {
711+ throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
925712 }
926- return hashCode;
927713 }
928714
929715 /**
930- * Returns an iterator over the elements in this list in proper sequence.
716+ * Throws <code>IndexOutOfBoundsException</code> if <code>index</code>
717+ * is out of the list bounds. Excluding the last element.
931718 *
932- * <p>The returned iterator provides a snapshot of the state of the list
933- * when the iterator was constructed. No synchronization is needed while
934- * traversing the iterator. The iterator does <em>NOT</em> support the
935- * <tt>remove</tt> method.
936- *
937- * @return an iterator over the elements in this list in proper sequence
719+ * @param index element index to check.
938720 */
939- public Iterator<E> iterator() {
940- return new COWIterator<E>(getArray(), 0);
721+ static final void checkIndexExlusive(int index, int size) {
722+ if (index < 0 || index >= size) {
723+ throw new IndexOutOfBoundsException("Index is " + index + ", size is " + size);
724+ }
941725 }
942726
943727 /**
944- * {@inheritDoc}
728+ * gets the internal data array
945729 *
946- * <p>The returned iterator provides a snapshot of the state of the list
947- * when the iterator was constructed. No synchronization is needed while
948- * traversing the iterator. The iterator does <em>NOT</em> support the
949- * <tt>remove</tt>, <tt>set</tt> or <tt>add</tt> methods.
730+ * @return the data array
950731 */
951- public ListIterator<E> listIterator() {
952- return new COWIterator<E>(getArray(), 0);
732+ final E[] getArray() {
733+ return arr;
953734 }
954735
955736 /**
956- * {@inheritDoc}
957- *
958- * <p>The returned iterator provides a snapshot of the state of the list
959- * when the iterator was constructed. No synchronization is needed while
960- * traversing the iterator. The iterator does <em>NOT</em> support the
961- * <tt>remove</tt>, <tt>set</tt> or <tt>add</tt> methods.
962- *
963- * @throws IndexOutOfBoundsException {@inheritDoc}
737+ * list iterator implementation,
738+ * when created gets snapshot of the list,
739+ * so never throws ConcurrentModificationException
964740 */
965- public ListIterator<E> listIterator(final int index) {
966- Object[] elements = getArray();
967- int len = elements.length;
968- if (index<0 || index>len)
969- throw new IndexOutOfBoundsException("Index: "+index);
741+ private static class ListIteratorImpl implements ListIterator {
742+ private final Object[] arr;
970743
971- return new COWIterator<E>(elements, index);
972- }
744+ private int current;
973745
974- private static class COWIterator<E> implements ListIterator<E> {
975- /** Snapshot of the array **/
976- private final Object[] snapshot;
977- /** Index of element to be returned by subsequent call to next. */
978- private int cursor;
746+ private final int size;
979747
980- private COWIterator(Object[] elements, int initialCursor) {
981- cursor = initialCursor;
982- snapshot = elements;
748+ final int size() {
749+ return size;
750+ }
751+
752+ public ListIteratorImpl(Object[] data, int current) {
753+ this.current = current;
754+ arr = data;
755+ size = data.length;
756+ }
757+
758+ public void add(Object o) {
759+ throw new UnsupportedOperationException("Unsupported operation add");
983760 }
984761
985762 public boolean hasNext() {
986- return cursor < snapshot.length;
763+ if (current < size) {
764+ return true;
765+ }
766+ return false;
987767 }
988768
989769 public boolean hasPrevious() {
990- return cursor > 0;
770+ return current > 0;
991771 }
992772
993- @SuppressWarnings("unchecked")
994- public E next() {
995- if (! hasNext())
996- throw new NoSuchElementException();
997- return (E) snapshot[cursor++];
773+ public Object next() {
774+ if (hasNext()) {
775+ return arr[current++];
776+ }
777+ throw new NoSuchElementException("pos is " + current + ", size is " + size);
998778 }
999779
1000- @SuppressWarnings("unchecked")
1001- public E previous() {
1002- if (! hasPrevious())
1003- throw new NoSuchElementException();
1004- return (E) snapshot[--cursor];
780+ public int nextIndex() {
781+ return current;
1005782 }
1006783
1007- public int nextIndex() {
1008- return cursor;
784+ public Object previous() {
785+ if (hasPrevious()) {
786+ return arr[--current];
787+ }
788+ throw new NoSuchElementException("pos is " + (current-1) + ", size is " + size);
1009789 }
1010790
1011791 public int previousIndex() {
1012- return cursor-1;
792+ return current - 1;
1013793 }
1014794
1015- /**
1016- * Not supported. Always throws UnsupportedOperationException.
1017- * @throws UnsupportedOperationException always; <tt>remove</tt>
1018- * is not supported by this iterator.
1019- */
1020795 public void remove() {
1021- throw new UnsupportedOperationException();
796+ throw new UnsupportedOperationException("Unsupported operation remove");
1022797 }
1023798
1024- /**
1025- * Not supported. Always throws UnsupportedOperationException.
1026- * @throws UnsupportedOperationException always; <tt>set</tt>
1027- * is not supported by this iterator.
1028- */
1029- public void set(E e) {
1030- throw new UnsupportedOperationException();
799+ public void set(Object o) {
800+ throw new UnsupportedOperationException("Unsupported operation set");
1031801 }
1032802
1033- /**
1034- * Not supported. Always throws UnsupportedOperationException.
1035- * @throws UnsupportedOperationException always; <tt>add</tt>
1036- * is not supported by this iterator.
1037- */
1038- public void add(E e) {
1039- throw new UnsupportedOperationException();
1040- }
1041803 }
1042804
1043805 /**
1044- * Returns a view of the portion of this list between
1045- * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive.
1046- * The returned list is backed by this list, so changes in the
1047- * returned list are reflected in this list.
1048- *
1049- * <p>The semantics of the list returned by this method become
1050- * undefined if the backing list (i.e., this list) is modified in
1051- * any way other than via the returned list.
1052- *
1053- * @param fromIndex low endpoint (inclusive) of the subList
1054- * @param toIndex high endpoint (exclusive) of the subList
1055- * @return a view of the specified range within this list
1056- * @throws IndexOutOfBoundsException {@inheritDoc}
806+ * Keeps a state of sublist implementation,
807+ * size and array declared as final,
808+ * so we'll never get the unconsistent state
1057809 */
1058- public List<E> subList(int fromIndex, int toIndex) {
1059- final ReentrantLock lock = this.lock;
1060- lock.lock();
1061- try {
1062- Object[] elements = getArray();
1063- int len = elements.length;
1064- if (fromIndex < 0 || toIndex > len || fromIndex > toIndex)
1065- throw new IndexOutOfBoundsException();
1066- return new COWSubList<E>(this, fromIndex, toIndex);
1067- } finally {
1068- lock.unlock();
810+ static final class SubListReadData {
811+ final int size;
812+
813+ final Object[] data;
814+
815+ SubListReadData(int size, Object[] data) {
816+ this.size = size;
817+ this.data = data;
1069818 }
1070819 }
1071820
1072821 /**
1073- * Sublist for CopyOnWriteArrayList.
1074- * This class extends AbstractList merely for convenience, to
1075- * avoid having to define addAll, etc. This doesn't hurt, but
1076- * is wasteful. This class does not need or use modCount
1077- * mechanics in AbstractList, but does need to check for
1078- * concurrent modification using similar mechanics. On each
1079- * operation, the array that we expect the backing list to use
1080- * is checked and updated. Since we do this for all of the
1081- * base operations invoked by those defined in AbstractList,
1082- * all is well. While inefficient, this is not worth
1083- * improving. The kinds of list operations inherited from
1084- * AbstractList are already so slow on COW sublists that
1085- * adding a bit more space/time doesn't seem even noticeable.
822+ * Represents a list returned by <code>sublist()</code>.
1086823 */
1087- private static class COWSubList<E>
1088- extends AbstractList<E>
1089- implements RandomAccess
1090- {
1091- private final CopyOnWriteArrayList<E> l;
1092- private final int offset;
1093- private int size;
1094- private Object[] expectedArray;
1095-
1096- // only call this holding l's lock
1097- COWSubList(CopyOnWriteArrayList<E> list,
1098- int fromIndex, int toIndex) {
1099- l = list;
1100- expectedArray = l.getArray();
1101- offset = fromIndex;
1102- size = toIndex - fromIndex;
1103- }
1104-
1105- // only call this holding l's lock
1106- private void checkForComodification() {
1107- if (l.getArray() != expectedArray)
824+ static class SubList implements List {
825+ private final CopyOnWriteArrayList list;
826+
827+ private volatile SubListReadData read;
828+
829+ private final int start;
830+
831+ /**
832+ * Sublist constructor.
833+ *
834+ * @param list backing list.
835+ * @param fromIdx startingIndex, inclusive
836+ * @param toIdx endIndex, exclusive
837+ */
838+ public SubList(CopyOnWriteArrayList list, int fromIdx, int toIdx) {
839+ this.list = list;
840+ Object[] data = list.getData();
841+ int size = toIdx - fromIdx;
842+ checkIndexExlusive(fromIdx, data.length);
843+ checkIndexInclusive(toIdx, data.length);
844+ read = new SubListReadData(size, list.getData());
845+ start = fromIdx;
846+ }
847+
848+ /**
849+ * throws ConcurrentModificationException when the list
850+ * is structurally modified in the other way other than via this subList
851+ * <p/>
852+ * Should be called under lock!
853+ */
854+ private void checkModifications() {
855+ if (read.data != list.getData()) {
1108856 throw new ConcurrentModificationException();
857+ }
1109858 }
1110859
1111- // only call this holding l's lock
1112- private void rangeCheck(int index) {
1113- if (index<0 || index>=size)
1114- throw new IndexOutOfBoundsException("Index: "+index+
1115- ",Size: "+size);
860+ /**
861+ * @see java.util.List#listIterator(int)
862+ */
863+ public ListIterator listIterator(int startIdx) {
864+ return new SubListIterator(startIdx, read);
1116865 }
1117866
1118- public E set(int index, E element) {
1119- final ReentrantLock lock = l.lock;
1120- lock.lock();
867+ /**
868+ * @see java.util.List#set(int, java.lang.Object)
869+ */
870+ public Object set(int index, Object obj) {
871+ list.lock.lock();
1121872 try {
1122- rangeCheck(index);
1123- checkForComodification();
1124- E x = l.set(index+offset, element);
1125- expectedArray = l.getArray();
1126- return x;
873+ checkIndexExlusive(index, read.size);
874+ checkModifications();
875+ Object result = list.set(index + start, obj);
876+ read = new SubListReadData(read.size, list.getData());
877+ return result;
1127878 } finally {
1128- lock.unlock();
879+ list.lock.unlock();
1129880 }
1130881 }
1131882
1132- public E get(int index) {
1133- final ReentrantLock lock = l.lock;
1134- lock.lock();
883+ /**
884+ * @see java.util.List#get(int)
885+ */
886+ public Object get(int index) {
887+ SubListReadData data = read;
888+ if (data.data != list.getData()) {
889+ list.lock.lock();
890+ try {
891+ data = read;
892+ if (data.data != list.getData()) {
893+ throw new ConcurrentModificationException();
894+ }
895+ } finally {
896+ list.lock.unlock();
897+ }
898+ }
899+ checkIndexExlusive(index, data.size);
900+ return data.data[index + start];
901+ }
902+
903+ /**
904+ * @see java.util.Collection#size()
905+ */
906+ public int size() {
907+ return read.size;
908+ }
909+
910+ /**
911+ * @see java.util.List#remove(int)
912+ */
913+ public Object remove(int index) {
914+ list.lock.lock();
1135915 try {
1136- rangeCheck(index);
1137- checkForComodification();
1138- return l.get(index+offset);
916+ checkIndexExlusive(index, read.size);
917+ checkModifications();
918+ Object obj = list.remove(index + start);
919+ read = new SubListReadData(read.size - 1, list.getData());
920+ return obj;
1139921 } finally {
1140- lock.unlock();
922+ list.lock.unlock();
1141923 }
1142924 }
1143925
1144- public int size() {
1145- final ReentrantLock lock = l.lock;
1146- lock.lock();
926+ /**
927+ * @see java.util.List#add(int, java.lang.Object)
928+ */
929+ public void add(int index, Object object) {
930+ list.lock.lock();
1147931 try {
1148- checkForComodification();
1149- return size;
932+ checkIndexInclusive(index, read.size);
933+ checkModifications();
934+ list.add(index + start, object);
935+ read = new SubListReadData(read.size + 1, list.getData());
1150936 } finally {
1151- lock.unlock();
937+ list.lock.unlock();
1152938 }
1153939 }
1154940
1155- public void add(int index, E element) {
1156- final ReentrantLock lock = l.lock;
1157- lock.lock();
941+ public boolean add(Object o) {
942+ list.lock.lock();
1158943 try {
1159- checkForComodification();
1160- if (index<0 || index>size)
1161- throw new IndexOutOfBoundsException();
1162- l.add(index+offset, element);
1163- expectedArray = l.getArray();
1164- size++;
944+ checkModifications();
945+ list.add(start + read.size, o);
946+ read = new SubListReadData(read.size + 1, list.getData());
947+ return true;
1165948 } finally {
1166- lock.unlock();
949+ list.lock.unlock();
1167950 }
1168951 }
1169952
1170- public void clear() {
1171- final ReentrantLock lock = l.lock;
1172- lock.lock();
953+ public boolean addAll(Collection c) {
954+ list.lock.lock();
1173955 try {
1174- checkForComodification();
1175- l.removeRange(offset, offset+size);
1176- expectedArray = l.getArray();
1177- size = 0;
956+ checkModifications();
957+ int d = list.size();
958+ list.addAll(start + read.size, c);
959+ read = new SubListReadData(read.size + (list.size() - d), list
960+ .getData());
961+ return true;
1178962 } finally {
1179- lock.unlock();
963+ list.lock.unlock();
1180964 }
1181965 }
1182966
1183- public E remove(int index) {
1184- final ReentrantLock lock = l.lock;
1185- lock.lock();
967+ public void clear() {
968+ list.lock.lock();
1186969 try {
1187- rangeCheck(index);
1188- checkForComodification();
1189- E result = l.remove(index+offset);
1190- expectedArray = l.getArray();
1191- size--;
1192- return result;
970+ checkModifications();
971+ list.removeRange(start, read.size);
972+ read = new SubListReadData(0, list.getData());
1193973 } finally {
1194- lock.unlock();
974+ list.lock.unlock();
1195975 }
1196976 }
1197977
1198- public boolean remove(Object o) {
1199- int index = indexOf(o);
1200- if (index == -1)
1201- return false;
1202- remove(index);
1203- return true;
978+ public boolean contains(Object o) {
979+ return indexOf(o) != -1;
980+ }
981+
982+ public boolean containsAll(Collection c) {
983+ SubListReadData b = read;
984+ return CopyOnWriteArrayList.containsAll(c, b.data, start, b.size);
1204985 }
1205986
1206- public Iterator<E> iterator() {
1207- final ReentrantLock lock = l.lock;
1208- lock.lock();
987+ public int indexOf(Object o) {
988+ SubListReadData b = read;
989+ int ind = CopyOnWriteArrayList.indexOf(o, b.data, start, b.size)
990+ - start;
991+ return ind < 0 ? -1 : ind;
992+ }
993+
994+ public boolean isEmpty() {
995+ return read.size == 0;
996+ }
997+
998+ public Iterator iterator() {
999+ return new SubListIterator(0, read);
1000+ }
1001+
1002+ public int lastIndexOf(Object o) {
1003+ SubListReadData b = read;
1004+ int ind = CopyOnWriteArrayList
1005+ .lastIndexOf(o, b.data, start, b.size)
1006+ - start;
1007+ return ind < 0 ? -1 : ind;
1008+ }
1009+
1010+ public ListIterator listIterator() {
1011+ return new SubListIterator(0, read);
1012+ }
1013+
1014+ public boolean remove(Object o) {
1015+ list.lock.lock();
12091016 try {
1210- checkForComodification();
1211- return new COWSubListIterator<E>(l, 0, offset, size);
1017+ checkModifications();
1018+ int i = indexOf(o);
1019+ if (i == -1) {
1020+ return false;
1021+ }
1022+ boolean result = list.remove(i + start) != null;
1023+ if (result) {
1024+ read = new SubListReadData(read.size - 1, list.getData());
1025+ }
1026+ return result;
12121027 } finally {
1213- lock.unlock();
1028+ list.lock.unlock();
12141029 }
12151030 }
12161031
1217- public ListIterator<E> listIterator(final int index) {
1218- final ReentrantLock lock = l.lock;
1219- lock.lock();
1032+ public boolean removeAll(Collection c) {
1033+ list.lock.lock();
12201034 try {
1221- checkForComodification();
1222- if (index<0 || index>size)
1223- throw new IndexOutOfBoundsException("Index: "+index+
1224- ", Size: "+size);
1225- return new COWSubListIterator<E>(l, index, offset, size);
1035+ checkModifications();
1036+ int removed = list.removeAll(c, start, read.size);
1037+ if (removed > 0) {
1038+ read = new SubListReadData(read.size - removed, list
1039+ .getData());
1040+ return true;
1041+ }
12261042 } finally {
1227- lock.unlock();
1043+ list.lock.unlock();
12281044 }
1045+ return false;
12291046 }
12301047
1231- public List<E> subList(int fromIndex, int toIndex) {
1232- final ReentrantLock lock = l.lock;
1233- lock.lock();
1048+ public boolean retainAll(Collection c) {
1049+ list.lock.lock();
12341050 try {
1235- checkForComodification();
1236- if (fromIndex<0 || toIndex>size)
1237- throw new IndexOutOfBoundsException();
1238- return new COWSubList<E>(l, fromIndex + offset,
1239- toIndex + offset);
1051+ checkModifications();
1052+ int removed = list.retainAll(c, start, read.size);
1053+ if (removed > 0) {
1054+ read = new SubListReadData(read.size - removed, list
1055+ .getData());
1056+ return true;
1057+ }
1058+ return false;
12401059 } finally {
1241- lock.unlock();
1060+ list.lock.unlock();
12421061 }
12431062 }
12441063
1245- }
1246-
1247-
1248- private static class COWSubListIterator<E> implements ListIterator<E> {
1249- private final ListIterator<E> i;
1250- private final int index;
1251- private final int offset;
1252- private final int size;
1253-
1254- COWSubListIterator(List<E> l, int index, int offset,
1255- int size) {
1256- this.index = index;
1257- this.offset = offset;
1258- this.size = size;
1259- i = l.listIterator(index+offset);
1064+ public List subList(int fromIndex, int toIndex) {
1065+ return new SubList(list, start + fromIndex, start + toIndex);
12601066 }
12611067
1262- public boolean hasNext() {
1263- return nextIndex() < size;
1068+ public Object[] toArray() {
1069+ SubListReadData r = read;
1070+ return CopyOnWriteArrayList.toArray(r.data, start, r.size);
12641071 }
12651072
1266- public E next() {
1267- if (hasNext())
1268- return i.next();
1269- else
1270- throw new NoSuchElementException();
1073+ public Object[] toArray(Object[] a) {
1074+ SubListReadData r = read;
1075+ return CopyOnWriteArrayList.toArray(a, r.data, start, r.size);
12711076 }
12721077
1273- public boolean hasPrevious() {
1274- return previousIndex() >= 0;
1078+ /**
1079+ * @see java.util.List#addAll(int, java.util.Collection)
1080+ */
1081+ public boolean addAll(int index, Collection collection) {
1082+ list.lock.lock();
1083+ try {
1084+ checkIndexInclusive(index, read.size);
1085+ checkModifications();
1086+ int d = list.size();
1087+ boolean rt = list.addAll(index + start, collection);
1088+ read = new SubListReadData(read.size + list.size() - d, list
1089+ .getData());
1090+ return rt;
1091+ } finally {
1092+ list.lock.unlock();
1093+ }
12751094 }
12761095
1277- public E previous() {
1278- if (hasPrevious())
1279- return i.previous();
1280- else
1281- throw new NoSuchElementException();
1282- }
1096+ /**
1097+ * Implementation of <code>ListIterator</code> for the
1098+ * <code>SubList</code>
1099+ * gets a snapshot of the sublist,
1100+ * never throws ConcurrentModificationException
1101+ */
1102+ private class SubListIterator extends ListIteratorImpl {
1103+ private final SubListReadData dataR;
1104+
1105+ /**
1106+ * Constructs an iterator starting with the given index
1107+ *
1108+ * @param index index of the first element to iterate.
1109+ */
1110+ private SubListIterator(int index, SubListReadData d) {
1111+ super(d.data, index + start);
1112+ this.dataR = d;
1113+ }
12831114
1284- public int nextIndex() {
1285- return i.nextIndex() - offset;
1286- }
1115+ /**
1116+ * @see java.util.ListIterator#nextIndex()
1117+ */
1118+ public int nextIndex() {
1119+ return super.nextIndex() - start;
1120+ }
12871121
1288- public int previousIndex() {
1289- return i.previousIndex() - offset;
1290- }
1122+ /**
1123+ * @see java.util.ListIterator#previousIndex()
1124+ */
1125+ public int previousIndex() {
1126+ return super.previousIndex() - start;
1127+ }
12911128
1292- public void remove() {
1293- throw new UnsupportedOperationException();
1294- }
1129+ /**
1130+ * @see java.util.Iterator#hasNext()
1131+ */
1132+ public boolean hasNext() {
1133+ return nextIndex() < dataR.size;
1134+ }
12951135
1296- public void set(E e) {
1297- throw new UnsupportedOperationException();
1136+ /**
1137+ * @see java.util.ListIterator#hasPrevious()
1138+ */
1139+ public boolean hasPrevious() {
1140+ return previousIndex() > -1;
1141+ }
12981142 }
12991143
1300- public void add(E e) {
1301- throw new UnsupportedOperationException();
1302- }
13031144 }
13041145
1305- // Support for resetting lock while deserializing
1306- private static final Unsafe unsafe = Unsafe.getUnsafe();
1307- private static final long lockOffset;
1308- static {
1309- try {
1310- lockOffset = unsafe.objectFieldOffset
1311- (CopyOnWriteArrayList.class.getDeclaredField("lock"));
1312- } catch (Exception ex) { throw new Error(ex); }
1146+ //serialization support
1147+ /**
1148+ * Writes the object state to the ObjectOutputStream.
1149+ *
1150+ * @param oos ObjectOutputStream to write object to.
1151+ * @throws IOException if an I/O error occur.
1152+ */
1153+ private void writeObject(ObjectOutputStream oos) throws IOException {
1154+ E[] back = getData();
1155+ int size = back.length;
1156+ oos.defaultWriteObject();
1157+ oos.writeInt(size);
1158+ for (int i = 0; i < size; i++) {
1159+ oos.writeObject(back[i]);
1160+ }
13131161 }
1314- private void resetLock() {
1315- unsafe.putObjectVolatile(this, lockOffset, new ReentrantLock());
1162+
1163+ /**
1164+ * Reads the object state from the ObjectOutputStream.
1165+ *
1166+ * @param ois ObjectInputStream to read object from.
1167+ * @throws IOException if an I/O error occur.
1168+ */
1169+ private void readObject(ObjectInputStream ois) throws IOException,
1170+ ClassNotFoundException {
1171+ ois.defaultReadObject();
1172+ int length = ois.readInt();
1173+ if (length == 0) {
1174+ setData(newElementArray(0));
1175+ } else {
1176+ E[] back = newElementArray(length);
1177+ for (int i = 0; i < back.length; i++) {
1178+ back[i] = (E) ois.readObject();
1179+ }
1180+ setData(back);
1181+ }
13161182 }
1183+
13171184 }
--- a/libcore/dalvik/src/main/java/dalvik/system/Zygote.java
+++ b/libcore/dalvik/src/main/java/dalvik/system/Zygote.java
@@ -109,12 +109,27 @@ public class Zygote {
109109 * dimension having a length of 3 and representing
110110 * (resource, rlim_cur, rlim_max). These are set via the posix
111111 * setrlimit(2) call.
112+ * @param permittedCapabilities argument for setcap()
113+ * @param effectiveCapabilities argument for setcap()
112114 *
113115 * @return 0 if this is the child, pid of the child
114116 * if this is the parent, or -1 on error.
117+ *
118+ * @hide
119+ */
120+ native public static int forkSystemServer(int uid, int gid,
121+ int[] gids, int debugFlags, int[][] rlimits,
122+ long permittedCapabilities, long effectiveCapabilities);
123+
124+ /*
125+ * For bug 3176774, we needed to update forkSystemServer() after
126+ * the API was locked down. To avoid going out of sync with the
127+ * API description file, we provide a dummy function here.
115128 */
116- native public static int forkSystemServer(int uid, int gid,
117- int[] gids, int debugFlags, int[][] rlimits);
129+ public static int forkSystemServer(int uid, int gid,
130+ int[] gids, int debugFlags, int[][] rlimits) {
131+ throw new UnsupportedOperationException();
132+ }
118133
119134 /**
120135 * Special method to start the system server process.
--- a/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java
+++ b/libcore/luni/src/test/java/org/apache/harmony/luni/tests/java/lang/ThreadTest.java
@@ -1999,10 +1999,13 @@ public class ThreadTest extends junit.framework.TestCase {
19991999
20002000 while (!sem.hasQueuedThreads()){}
20012001
2002+ long start = System.currentTimeMillis();
2003+ while(start + 1000 > System.currentTimeMillis()) {}
20022004 assertEquals(Thread.State.WAITING, th.getState());
2005+
20032006 synchronized (lock) {
20042007 sem.release();
2005- long start = System.currentTimeMillis();
2008+ start = System.currentTimeMillis();
20062009 while(start + 1000 > System.currentTimeMillis()) {}
20072010 assertEquals(Thread.State.BLOCKED, th.getState());
20082011 }
--- a/libcore/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java
+++ b/libcore/security/src/test/java/org/apache/harmony/security/tests/java/security/CodeSourceTest.java
@@ -40,23 +40,14 @@ import java.security.cert.Certificate;
4040 import org.apache.harmony.security.tests.support.TestCertUtils;
4141
4242 import junit.framework.TestCase;
43+
4344 @TestTargetClass(CodeSource.class)
4445 /**
4546 * Unit test for CodeSource.
46- *
47+ *
4748 */
4849
4950 public class CodeSourceTest extends TestCase {
50- /**
51- *
52- * Entry point for standalone runs.
53- *
54- * @param args command line arguments
55- */
56- public static void main(String[] args) throws Exception {
57- junit.textui.TestRunner.run(CodeSourceTest.class);
58- }
59-
6051 private java.security.cert.Certificate[] chain = null;
6152
6253 /* Below are various URLs used during the testing */
@@ -83,7 +74,7 @@ public class CodeSourceTest extends TestCase {
8374 private static URL urlFileDirStar;
8475
8576 private static URL urlRef1, urlRef2;
86-
77+
8778 private boolean init = false;
8879
8980 private void init() {
@@ -92,28 +83,28 @@ public class CodeSourceTest extends TestCase {
9283 String siteName = "www.intel.com";
9384 InetAddress addr = InetAddress.getByName(siteName);
9485 String siteIP = addr.getHostAddress();
95-
86+
9687 urlSite = new URL("http://"+siteName+"");
9788 urlDir = new URL("http://"+siteName+"/drl_test");
9889 urlDirOtherSite = new URL("http://www.any-other-site-which-is-not-siteName.com/drl_test");
99-
90+
10091 urlDir_port80 = new URL("http://"+siteName+":80/drl_test");
10192 urlDir_port81 = new URL("http://"+siteName+":81/drl_test");
10293 urlDirWithSlash = new URL(urlDir + "/");
103-
94+
10495 //urlDirFtp = new URL("ftp://www.intel.com/drl_test");
10596 urlDir_FileProtocol = new URL("file://"+siteName+"/drl_test");
106-
97+
10798 urlDirIP = new URL("http://"+siteIP+"/drl_test");
108-
99+
109100 urlFile = new URL("http://"+siteName+"/drl_test/empty.jar");
110101 urlFileWithAdditionalDirs = new URL(
111102 "http://"+siteName+"/drl_test/what/ever/here/empty.jar");
112-
103+
113104 urlFileDirMinus = new URL("http://"+siteName+"/drl_test/-");
114105 urlFileDirStar = new URL("http://"+siteName+"/drl_test/*");
115106 urlFileDirOtherDir = new URL("http://"+siteName+"/_test_drl_/*");
116-
107+
117108 urlRef1 = new URL("http://"+siteName+"/drl_test/index.html#ref1");
118109 urlRef2 = new URL("http://"+siteName+"/drl_test/index.html#ref2");
119110 } catch (MalformedURLException ex) {
@@ -134,7 +125,7 @@ public class CodeSourceTest extends TestCase {
134125
135126 /**
136127 * Tests hashCode().<br>
137- * javadoc says nothing, so test DRL-specific implementation.
128+ * javadoc says nothing, so test DRL-specific implementation.
138129 */
139130 @TestTargetNew(
140131 level = TestLevel.COMPLETE,
@@ -143,7 +134,7 @@ public class CodeSourceTest extends TestCase {
143134 args = {}
144135 )
145136 public void testHashCode() {
146- // when nothing is specified, then hashCode obviously must be 0.
137+ // when nothing is specified, then hashCode obviously must be 0.
147138 assertTrue(new CodeSource(null, (Certificate[]) null).hashCode() == 0);
148139 // only URL.hashCode is taken into account...
149140 assertTrue(new CodeSource(urlSite, (Certificate[]) null).hashCode() == urlSite
@@ -217,7 +208,7 @@ public class CodeSourceTest extends TestCase {
217208
218209 /**
219210 * Test for equals(Object)<br>
220- * The signer certificate chain must contain the same set of certificates, but
211+ * The signer certificate chain must contain the same set of certificates, but
221212 * the order of the certificates is not taken into account.
222213 */
223214 @TestTargetNew(
@@ -238,7 +229,7 @@ public class CodeSourceTest extends TestCase {
238229
239230 /**
240231 * Test for equals(Object)<br>
241- * Checks that both 'null' and not-null URLs are taken into account - properly.
232+ * Checks that both 'null' and not-null URLs are taken into account - properly.
242233 */
243234 @TestTargetNew(
244235 level = TestLevel.PARTIAL_COMPLETE,
@@ -277,7 +268,7 @@ public class CodeSourceTest extends TestCase {
277268 }
278269
279270 /**
280- * Tests whether the getCertificates() returns certificates obtained from
271+ * Tests whether the getCertificates() returns certificates obtained from
281272 * the signers.
282273 */
283274 @TestTargetNew(
@@ -295,19 +286,19 @@ public class CodeSourceTest extends TestCase {
295286 CodeSigner[] signers = { new CodeSigner(cpath, null) };
296287 CodeSource cs = new CodeSource(null, signers);
297288 Certificate[] got = cs.getCertificates();
298- // The set of certificates must be exactly the same,
289+ // The set of certificates must be exactly the same,
299290 // but the order is not specified
300291 assertTrue(presented(certs, got));
301292 assertTrue(presented(got, certs));
302293 }
303294
304295 /**
305- * Checks whether two arrays of certificates represent the same same set of
296+ * Checks whether two arrays of certificates represent the same same set of
306297 * certificates - in the same order.
307- * @param one first array
298+ * @param one first array
308299 * @param two second array
309- * @return <code>true</code> if both arrays represent the same set of
310- * certificates,
300+ * @return <code>true</code> if both arrays represent the same set of
301+ * certificates,
311302 * <code>false</code> otherwise.
312303 */
313304 private static boolean checkEqual(java.security.cert.Certificate[] one,
@@ -342,10 +333,10 @@ public class CodeSourceTest extends TestCase {
342333 /**
343334 * Performs a test whether the <code>what</code> certificates are all
344335 * presented in <code>where</code> certificates.
345- *
336+ *
346337 * @param what - first array of Certificates
347338 * @param where - second array of Certificates
348- * @return <code>true</code> if each and every certificate from 'what'
339+ * @return <code>true</code> if each and every certificate from 'what'
349340 * (including null) is presented in 'where' <code>false</code> otherwise
350341 */
351342 private static boolean presented(Certificate[] what, Certificate[] where) {
@@ -413,7 +404,7 @@ public class CodeSourceTest extends TestCase {
413404 assertTrue(found);
414405 }
415406 }
416-
407+
417408 /**
418409 * Tests CodeSource.getCodeSigners() for null.
419410 */
@@ -424,7 +415,7 @@ public class CodeSourceTest extends TestCase {
424415 args = {}
425416 )
426417 public void testGetCoderSignersNull() throws Exception{
427- assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners()); //$NON-NLS-1$
418+ assertNull(new CodeSource(new URL("http://url"), (Certificate[])null).getCodeSigners());
428419 }
429420
430421 /**
@@ -453,7 +444,7 @@ public class CodeSourceTest extends TestCase {
453444 args = {}
454445 )
455446 public void testToString() {
456- // Javadoc keeps silence about String's format,
447+ // Javadoc keeps silence about String's format,
457448 // just make sure it can be invoked.
458449 new CodeSource(urlSite, chain).toString();
459450 new CodeSource(null, chain).toString();
@@ -462,9 +453,9 @@ public class CodeSourceTest extends TestCase {
462453
463454 /**
464455 * Tests whether we are running with the 1.5 features.<br>
465- * The test is preformed by looking for (via reflection) the CodeSource's
456+ * The test is preformed by looking for (via reflection) the CodeSource's
466457 * constructor {@link CodeSource#CodeSource(URL, CodeSigner[])}.
467- * @return <code>true</code> if 1.5 feature is presented, <code>false</code>
458+ * @return <code>true</code> if 1.5 feature is presented, <code>false</code>
468459 * otherwise.
469460 */
470461 private static boolean has_15_features() {
@@ -473,7 +464,7 @@ public class CodeSourceTest extends TestCase {
473464 try {
474465 klass.getConstructor(ctorArgs);
475466 } catch (NoSuchMethodException ex) {
476- // NoSuchMethod == Not RI.v1.5 and not DRL
467+ // NoSuchMethod == Not RI.v1.5 and not DRL
477468 return false;
478469 }
479470 return true;
@@ -512,9 +503,6 @@ public class CodeSourceTest extends TestCase {
512503 assertFalse(thizCS.implies(thatCS));
513504 }
514505
515- /**
516- * If this object's location equals codesource's location, then return true.
517- */
518506 @TestTargetNew(
519507 level = TestLevel.PARTIAL_COMPLETE,
520508 notes = "",
@@ -530,10 +518,6 @@ public class CodeSourceTest extends TestCase {
530518
531519 }
532520
533- /**
534- * This object's protocol (getLocation().getProtocol()) must be equal to
535- * codesource's protocol.
536- */
537521 /*
538522 * FIXME
539523 * commented out for temporary, as there is no FTP:// protocol supported yet.
@@ -559,11 +543,6 @@ public class CodeSourceTest extends TestCase {
559543 assertFalse(thatCS.implies(thizCS));
560544 }
561545
562- /**
563- * If this object's host (getLocation().getHost()) is not null, then the
564- * SocketPermission constructed with this object's host must imply the
565- * SocketPermission constructed with codesource's host.
566- */
567546 @TestTargetNew(
568547 level = TestLevel.PARTIAL_COMPLETE,
569548 notes = "",
@@ -577,7 +556,7 @@ public class CodeSourceTest extends TestCase {
577556 assertTrue(thizCS.implies(thatCS));
578557 assertTrue(thatCS.implies(thizCS));
579558
580- //
559+ //
581560 // Check for another site - force to create SocketPermission
582561 //
583562 thatCS = new CodeSource(urlDirOtherSite, (Certificate[]) null);
@@ -595,10 +574,6 @@ public class CodeSourceTest extends TestCase {
595574 assertFalse(thatCS.implies(thizCS));
596575 }
597576
598- /**
599- * If this object's port (getLocation().getPort()) is not equal to -1 (that
600- * is, if a port is specified), it must equal codesource's port.
601- */
602577 @TestTargetNew(
603578 level = TestLevel.PARTIAL_COMPLETE,
604579 notes = "",
@@ -626,10 +601,6 @@ public class CodeSourceTest extends TestCase {
626601 assertFalse(thizCS.implies(thatCS));
627602 }
628603
629- /**
630- * If this object's file (getLocation().getFile()) doesn't equal
631- * codesource's file, then the following checks are made: ...
632- */
633604 @TestTargetNew(
634605 level = TestLevel.PARTIAL_COMPLETE,
635606 notes = "",
@@ -642,10 +613,6 @@ public class CodeSourceTest extends TestCase {
642613 assertTrue(thizCS.implies(thatCS));
643614 }
644615
645- /**
646- * ... If this object's file ends with "/-", then codesource's file must
647- * start with this object's file (exclusive the trailing "-").
648- */
649616 @TestTargetNew(
650617 level = TestLevel.PARTIAL_COMPLETE,
651618 notes = "",
@@ -664,11 +631,6 @@ public class CodeSourceTest extends TestCase {
664631 assertFalse(thiz.implies(that));
665632 }
666633
667- /**
668- * ... If this object's file ends with a "/*", then codesource's file must
669- * start with this object's file and must not have any further "/"
670- * separators.
671- */
672634 @TestTargetNew(
673635 level = TestLevel.PARTIAL_COMPLETE,
674636 notes = "",
@@ -690,10 +652,6 @@ public class CodeSourceTest extends TestCase {
690652 assertFalse(thiz.implies(that));
691653 }
692654
693- /**
694- * ... If this object's file doesn't end with a "/", then codesource's file
695- * must match this object's file with a '/' appended.
696- */
697655 @TestTargetNew(
698656 level = TestLevel.PARTIAL_COMPLETE,
699657 notes = "",
@@ -708,10 +666,6 @@ public class CodeSourceTest extends TestCase {
708666 assertFalse(thatCS.implies(thizCS));
709667 }
710668
711- /**
712- * If this object's reference (getLocation().getRef()) is not null, it must
713- * equal codesource's reference.
714- */
715669 @TestTargetNew(
716670 level = TestLevel.PARTIAL_COMPLETE,
717671 notes = "",
@@ -754,7 +708,7 @@ public class CodeSourceTest extends TestCase {
754708
755709 //
756710 that = new CodeSource(urlSite, (Certificate[]) null);
757- // 'thiz' has set of certs, while 'that' has no certs. URL-s are the
711+ // 'thiz' has set of certs, while 'that' has no certs. URL-s are the
758712 // same.
759713 assertFalse(thiz.implies(that));
760714 assertTrue(that.implies(thiz));
@@ -762,8 +716,8 @@ public class CodeSourceTest extends TestCase {
762716
763717 /**
764718 * Testing with special URLs like 'localhost', 'file://' scheme ...
765- * These special URLs have a special processing in implies(),
766- * so they need to be covered and performance need to be checked
719+ * These special URLs have a special processing in implies(),
720+ * so they need to be covered and performance need to be checked
767721 */
768722 @TestTargetNew(
769723 level = TestLevel.PARTIAL_COMPLETE,
@@ -783,8 +737,8 @@ public class CodeSourceTest extends TestCase {
783737
784738 /**
785739 * Testing with special URLs like 'localhost', 'file://' scheme ...
786- * These special URLs have a special processing in implies(),
787- * so they need to be covered and performance need to be checked
740+ * These special URLs have a special processing in implies(),
741+ * so they need to be covered and performance need to be checked
788742 */
789743 @TestTargetNew(
790744 level = TestLevel.PARTIAL_COMPLETE,
--- a/libcore/security/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
+++ b/libcore/security/src/test/java/org/bouncycastle/jce/provider/PKIXCertPathValidatorSpiTest.java
@@ -1,65 +1,174 @@
1-// Copyright 2009 Google Inc. All Rights Reserved.
1+/*
2+ * Copyright (C) 2011 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
216
317 package org.bouncycastle.jce.provider;
418
19+import java.io.ByteArrayInputStream;
20+import java.io.ByteArrayOutputStream;
21+import java.security.cert.CertificateFactory;
22+import java.security.cert.X509Certificate;
23+import javax.security.auth.x500.X500Principal;
524 import junit.framework.TestCase;
6-import org.apache.harmony.security.provider.cert.X509CertImpl;
7-import org.apache.harmony.security.provider.cert.X509CertPathImpl;
8-import org.bouncycastle.asn1.x509.X509CertificateStructure;
9-import org.bouncycastle.asn1.ASN1Sequence;
10-import org.bouncycastle.asn1.ASN1InputStream;
1125
1226 import java.io.IOException;
13-import java.util.Arrays;
14-import java.util.Set;
15-import java.util.HashSet;
16-import java.security.cert.CertificateException;
17-import java.security.cert.TrustAnchor;
18-import java.security.cert.CertPathValidatorException;
19-import java.security.KeyStoreException;
20-import java.security.InvalidAlgorithmParameterException;
27+import java.io.ObjectInputStream;
28+import java.io.ObjectOutputStream;
29+import static junit.framework.Assert.assertEquals;
30+import static junit.framework.Assert.fail;
31+import junit.framework.AssertionFailedError;
2132
2233 /**
2334 * Verify the behavior of PKIXCertPathValidatorSpi.
2435 */
2536 public class PKIXCertPathValidatorSpiTest extends TestCase {
2637
38+ public void testSerialization() {
39+ String expected = "aced0005737200266a617661782e73656375726974792e617574682e7"
40+ + "83530302e583530305072696e636970616cf90dff3c88b877c703000078707572"
41+ + "00025b42acf317f8060854e002000078700000006a30683117301506035504031"
42+ + "30e7777772e676f6f676c652e636f6d31133011060355040a130a476f6f676c65"
43+ + "20496e63311630140603550407130d4d6f756e7461696e2056696577311330110"
44+ + "603550408130a43616c69666f726e6961310b300906035504061302555378";
45+ X500Principal actual = new X500Principal("C=US, "
46+ + "ST=California, "
47+ + "L=Mountain View, "
48+ + "O=Google Inc, "
49+ + "CN=www.google.com");
50+ new SerializableTester<X500Principal>(actual, expected).test();
51+ }
52+
2753 /**
28- * A chain of 3 ASN1-encoded certificates for https://service.sprint.com.
29- * The certificate subjects are "service.sprint.com", "Entrust Certification
30- * Authority - L1B", and "Entrust.net Certification Authority (2048)". The
31- * last certificate uses UTF8 encoding for its X509 name.
54+ * ASN1-encoded trusted certificate #946059622 for
55+ * Entrust.net. This certificate uses the T61String (aka
56+ * TeletexString or TELETEXSTRING) encoding for one
57+ * organizationalUnitNames:
58+ *
59+ * "www.entrust.net/CPS_2048 incorp. by ref. (limits liab.)"
3260 */
33- private final byte[][] serviceSprintComCertChain = new byte[][] {
34- 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 },
35- 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 },
36- 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 },
37- };
61+ 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 };
3862
3963 /**
40- * ASN1-encoded trusted certificate #946059622 for Entrust.net. This
41- * certificate uses the TELETEX encoding for its X509 name.
64+ * Confirm DRLCertFactory uses a non-hex format for T61String encoding: http://b/2102191
4265 */
43- 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 };
66+ public void testGetName() throws Exception {
67+ CertificateFactory certFactBC = CertificateFactory.getInstance("X.509", "BC");
68+ CertificateFactory certFactDRL = CertificateFactory.getInstance("X.509", "DRLCertFactory");
69+
70+ X509Certificate certBC = (X509Certificate)
71+ certFactBC.generateCertificate(new ByteArrayInputStream(T61STRING_CERT));
72+ X509Certificate certDRL = (X509Certificate)
73+ certFactDRL.generateCertificate(new ByteArrayInputStream(T61STRING_CERT));
74+
75+ assertEquals(certBC, certDRL);
76+
77+ assertEquals(certBC.getSubjectX500Principal(), certBC.getSubjectX500Principal());
78+ assertEquals(certDRL.getIssuerX500Principal(), certDRL.getIssuerX500Principal());
79+
80+ assertEquals(certBC.getSubjectX500Principal(), certDRL.getSubjectX500Principal());
81+ assertEquals(certBC.getIssuerX500Principal(), certDRL.getIssuerX500Principal());
82+
83+ String[] formats = {
84+ X500Principal.CANONICAL,
85+ X500Principal.RFC1779,
86+ X500Principal.RFC2253
87+ };
88+ for (String format : formats) {
89+ assertEquals(certBC.getSubjectX500Principal().getName(format),
90+ certDRL.getSubjectX500Principal().getName(format));
91+ assertEquals(certBC.getIssuerX500Principal().getName(format),
92+ certDRL.getIssuerX500Principal().getName(format));
93+ }
94+ String expected = ""
95+ + "cn=entrust.net certification authority (2048),"
96+ + "ou=(c) 1999 entrust.net limited,"
97+ + "ou=www.entrust.net/cps_2048 incorp. by ref. (limits liab.),"
98+ + "o=entrust.net";
99+ assertEquals(expected,
100+ certBC.getSubjectX500Principal().getName(X500Principal.CANONICAL));
101+
102+ }
103+}
104+
105+class SerializableTester<T> {
44106
45- public void testTrustAndRemoteCertificatesWithDifferentEncodings()
46- throws IOException, CertificateException, KeyStoreException,
47- InvalidAlgorithmParameterException, CertPathValidatorException {
107+ private final String golden;
108+ private final T value;
48109
49- X509CertPathImpl certPath = new X509CertPathImpl(Arrays.asList(
50- new X509CertImpl(serviceSprintComCertChain[0]),
51- new X509CertImpl(serviceSprintComCertChain[1]),
52- new X509CertImpl(serviceSprintComCertChain[2])));
110+ public SerializableTester(T value, String golden) {
111+ this.golden = golden;
112+ this.value = value;
113+ }
114+
115+ protected void verify(T deserialized) {}
116+
117+ public void test() {
118+ try {
119+ if (golden == null || golden.length() == 0) {
120+ fail("No golden value supplied! Consider using this: "
121+ + hexEncode(serialize(value)));
122+ }
123+
124+ // just a sanity check! if this fails, verify() is probably broken
125+ verify(value);
126+
127+ @SuppressWarnings("unchecked") // deserialize should return the proper type
128+ T deserialized = (T) deserialize(hexDecode(golden));
129+ assertEquals("User-constructed value doesn't equal deserialized golden value",
130+ value, deserialized);
131+ verify(deserialized);
132+
133+ @SuppressWarnings("unchecked") // deserialize should return the proper type
134+ T reserialized = (T) deserialize(serialize(value));
135+ assertEquals("User-constructed value doesn't equal itself, reserialized",
136+ value, reserialized);
137+ verify(reserialized);
53138
54- Set<TrustAnchor> trustAnchors = new HashSet<TrustAnchor>();
55- trustAnchors.add(new TrustAnchor(new X509CertificateObject(
56- new X509CertificateStructure(
57- (ASN1Sequence) new ASN1InputStream(trustedCert).readObject())), null));
139+ } catch (Exception e) {
140+ Error failure = new AssertionFailedError();
141+ failure.initCause(e);
142+ throw failure;
143+ }
144+ }
145+
146+ private byte[] serialize(Object object) throws IOException {
147+ ByteArrayOutputStream out = new ByteArrayOutputStream();
148+ new ObjectOutputStream(out).writeObject(object);
149+ return out.toByteArray();
150+ }
58151
59- IndexedPKIXParameters indexedPKIXParameters = new IndexedPKIXParameters(trustAnchors);
60- indexedPKIXParameters.setRevocationEnabled(false);
152+ private Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
153+ ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
154+ Object result = in.readObject();
155+ assertEquals(-1, in.read());
156+ return result;
157+ }
158+
159+ private String hexEncode(byte[] bytes) {
160+ StringBuilder result = new StringBuilder(bytes.length * 2);
161+ for (byte b : bytes) {
162+ result.append(String.format("%02x", b));
163+ }
164+ return result.toString();
165+ }
61166
62- new PKIXCertPathValidatorSpi().engineValidate(certPath, indexedPKIXParameters);
63- // completing normally indicates that the certificate was valid
167+ private byte[] hexDecode(String s) {
168+ byte[] result = new byte[s.length() / 2];
169+ for (int i = 0; i < result.length; i++) {
170+ result[i] = (byte) Integer.parseInt(s.substring(i*2, i*2 + 2), 16);
171+ }
172+ return result;
64173 }
65174 }
--- a/libcore/security/src/test/java/tests/api/javax/security/auth/SubjectTest.java
+++ b/libcore/security/src/test/java/tests/api/javax/security/auth/SubjectTest.java
@@ -39,16 +39,13 @@ import java.security.AccessControlContext;
3939 import java.security.AccessController;
4040 import java.security.ProtectionDomain;
4141
42-import org.apache.harmony.security.tests.support.acl.PrincipalImpl;
43-
44-
4542 /**
4643 * Tests for <code>Subject</code> class constructors and methods.
47- *
44+ *
4845 */
49-@TestTargetClass(Subject.class)
46+@TestTargetClass(Subject.class)
5047 public class SubjectTest extends TestCase {
51-
48+
5249 SecurityManager old;
5350
5451 @Override
@@ -64,7 +61,7 @@ public class SubjectTest extends TestCase {
6461 }
6562
6663 /**
67- * @tests javax.security.auth.Subject#Subject()
64+ * @tests javax.security.auth.Subject#Subject()
6865 */
6966 @TestTargetNew(
7067 level = TestLevel.COMPLETE,
@@ -83,83 +80,7 @@ public class SubjectTest extends TestCase {
8380 fail("Unexpected exception: " + e);
8481 }
8582 }
86-
87- /**
88- * @tests javax.security.auth.Subject#Subject(boolean readOnly,
89- * Set<? extends Principal> principals,
90- * Set<?> pubCredentials,
91- * Set<?> privCredentials)
92- */
93- @TestTargetNew(
94- level = TestLevel.COMPLETE,
95- notes = "",
96- method = "Subject",
97- args = {boolean.class, Set.class, Set.class, Set.class}
98- )
99- public void test_Constructor_02() {
100- Set <Principal> principal = new HashSet<Principal>();
101- Set <Object> pubCredentials = new HashSet<Object>();
102- Set <Object> privCredentials = new HashSet<Object>();
103- Principal pr1 = new PrincipalImpl("TestPrincipal1");
104- Principal pr2 = new PrincipalImpl("TestPrincipal2");
105- principal.add(pr1);
106- principal.add(pr2);
107- Object pubCredential1 = new Object();
108- Object pubCredential2 = new Object();
109- pubCredentials.add(pubCredential1);
110- pubCredentials.add(pubCredential2);
111- Object privCredential1 = new Object();
112- Object privCredential2 = new Object();
113- privCredentials.add(privCredential1);
114- privCredentials.add(privCredential2);
115-
116- try {
117- Subject s = new Subject(true, principal, pubCredentials, privCredentials);
118- assertNotNull("Null object returned", s);
119- assertTrue("Not read-only object", s.isReadOnly());
120- assertFalse("Set of principal is empty", s.getPrincipals().isEmpty());
121- assertFalse("Set of private credentials is empty", s.getPrivateCredentials().isEmpty());
122- assertFalse("Set of public credentials is empty", s.getPublicCredentials().isEmpty());
123- } catch (Exception e) {
124- fail("Unexpected exception: " + e);
125- }
126-
127- try {
128- Subject s = new Subject(false, principal, pubCredentials, privCredentials);
129- assertNotNull("Null object returned", s);
130- assertFalse("Read-only object", s.isReadOnly());
131- assertFalse("Set of principal is empty", s.getPrincipals().isEmpty());
132- assertFalse("Set of private credentials is empty", s.getPrivateCredentials().isEmpty());
133- assertFalse("Set of public credentials is empty", s.getPublicCredentials().isEmpty());
134- } catch (Exception e) {
135- fail("Unexpected exception: " + e);
136- }
137-
138- try {
139- Subject s = new Subject(true, null, pubCredentials, privCredentials);
140- fail("NullPointerException wasn't thrown");
141- } catch (NullPointerException npe) {
142- }
143-
144- try {
145- Subject s = new Subject(true, principal, null, privCredentials);
146- fail("NullPointerException wasn't thrown");
147- } catch (NullPointerException npe) {
148- }
149-
150- try {
151- Subject s = new Subject(true, principal, pubCredentials, null);
152- fail("NullPointerException wasn't thrown");
153- } catch (NullPointerException npe) {
154- }
155-
156- try {
157- Subject s = new Subject(true, null, null, null);
158- fail("NullPointerException wasn't thrown");
159- } catch (NullPointerException npe) {
160- }
161- }
162-
83+
16384 /**
16485 * @tests javax.security.auth.Subject#doAs(Subject subject, PrivilegedAction action)
16586 */
@@ -173,44 +94,26 @@ public class SubjectTest extends TestCase {
17394 Subject subj = new Subject();
17495 PrivilegedAction<Object> pa = new myPrivilegedAction();
17596 PrivilegedAction<Object> paNull = null;
176-
97+
17798 try {
17899 Object obj = Subject.doAs(null, pa);
179100 } catch (Exception e) {
180101 fail("Unexpected exception: " + e);
181102 }
182-
103+
183104 try {
184105 Object obj = Subject.doAs(subj, pa);
185106 } catch (Exception e) {
186107 fail("Unexpected exception: " + e);
187108 }
188-
109+
189110 try {
190111 Object obj = Subject.doAs(subj, paNull);
191112 fail("NullPointerException wasn't thrown");
192113 } catch (NullPointerException npe) {
193114 }
194-
195- class TestSecurityManager extends SecurityManager {
196- @Override
197- public void checkPermission(Permission permission) {
198- if (permission instanceof AuthPermission
199- && "doAs".equals(permission.getName())) {
200- throw new SecurityException();
201- }
202- super.checkPermission(permission);
203- }
204- }
205- TestSecurityManager s = new TestSecurityManager();
206- System.setSecurityManager(s);
207- try {
208- Object obj = Subject.doAs(subj, pa);
209- fail("SecurityException wasn't thrown");
210- } catch (SecurityException se) {
211- }
212115 }
213-
116+
214117 /**
215118 * @tests javax.security.auth.Subject#doAs(Subject subject, PrivilegedExceptionAction action)
216119 */
@@ -224,19 +127,19 @@ public class SubjectTest extends TestCase {
224127 Subject subj = new Subject();
225128 PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
226129 PrivilegedExceptionAction<Object> peaNull = null;
227-
130+
228131 try {
229132 Object obj = Subject.doAs(null, pea);
230133 } catch (Exception e) {
231134 fail("Unexpected exception: " + e);
232135 }
233-
136+
234137 try {
235138 Object obj = Subject.doAs(subj, pea);
236139 } catch (Exception e) {
237140 fail("Unexpected exception: " + e);
238141 }
239-
142+
240143 try {
241144 Object obj = Subject.doAs(subj, peaNull);
242145 fail("NullPointerException wasn't thrown");
@@ -244,7 +147,7 @@ public class SubjectTest extends TestCase {
244147 } catch (Exception e) {
245148 fail(e + " was thrown instead of NullPointerException");
246149 }
247-
150+
248151 try {
249152 Subject.doAs(subj, new PrivilegedExceptionAction<Object>(){
250153 public Object run() throws PrivilegedActionException {
@@ -254,30 +157,10 @@ public class SubjectTest extends TestCase {
254157 fail("PrivilegedActionException wasn't thrown");
255158 } catch (PrivilegedActionException e) {
256159 }
257-
258- class TestSecurityManager extends SecurityManager {
259- @Override
260- public void checkPermission(Permission permission) {
261- if (permission instanceof AuthPermission
262- && "doAs".equals(permission.getName())) {
263- throw new SecurityException();
264- }
265- super.checkPermission(permission);
266- }
267- }
268- TestSecurityManager s = new TestSecurityManager();
269- System.setSecurityManager(s);
270- try {
271- Object obj = Subject.doAs(subj, pea);
272- fail("SecurityException wasn't thrown");
273- } catch (SecurityException se) {
274- } catch (Exception e) {
275- fail(e + " was thrown instead of SecurityException");
276- }
277160 }
278-
161+
279162 /**
280- * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
163+ * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
281164 * PrivilegedAction action,
282165 * AccessControlContext acc)
283166 */
@@ -292,46 +175,28 @@ public class SubjectTest extends TestCase {
292175 PrivilegedAction<Object> pa = new myPrivilegedAction();
293176 PrivilegedAction<Object> paNull = null;
294177 AccessControlContext acc = AccessController.getContext();
295-
178+
296179 try {
297180 Object obj = Subject.doAsPrivileged(null, pa, acc);
298181 } catch (Exception e) {
299182 fail("Unexpected exception: " + e);
300183 }
301-
184+
302185 try {
303186 Object obj = Subject.doAsPrivileged(subj, pa, acc);
304187 } catch (Exception e) {
305188 fail("Unexpected exception: " + e);
306189 }
307-
190+
308191 try {
309192 Object obj = Subject.doAsPrivileged(subj, paNull, acc);
310193 fail("NullPointerException wasn't thrown");
311194 } catch (NullPointerException npe) {
312195 }
313-
314- class TestSecurityManager extends SecurityManager {
315- @Override
316- public void checkPermission(Permission permission) {
317- if (permission instanceof AuthPermission
318- && "doAsPrivileged".equals(permission.getName())) {
319- throw new SecurityException();
320- }
321- super.checkPermission(permission);
322- }
323- }
324- TestSecurityManager s = new TestSecurityManager();
325- System.setSecurityManager(s);
326- try {
327- Object obj = Subject.doAsPrivileged(subj, pa, acc);
328- fail("SecurityException wasn't thrown");
329- } catch (SecurityException se) {
330- }
331196 }
332-
197+
333198 /**
334- * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
199+ * @tests javax.security.auth.Subject#doAsPrivileged(Subject subject,
335200 * PrivilegedExceptionAction action,
336201 * AccessControlContext acc)
337202 */
@@ -346,19 +211,19 @@ public class SubjectTest extends TestCase {
346211 PrivilegedExceptionAction<Object> pea = new myPrivilegedExceptionAction();
347212 PrivilegedExceptionAction<Object> peaNull = null;
348213 AccessControlContext acc = AccessController.getContext();
349-
214+
350215 try {
351216 Object obj = Subject.doAsPrivileged(null, pea, acc);
352217 } catch (Exception e) {
353218 fail("Unexpected exception: " + e);
354219 }
355-
220+
356221 try {
357222 Object obj = Subject.doAsPrivileged(subj, pea, acc);
358223 } catch (Exception e) {
359224 fail("Unexpected exception: " + e);
360225 }
361-
226+
362227 try {
363228 Object obj = Subject.doAsPrivileged(subj, peaNull, acc);
364229 fail("NullPointerException wasn't thrown");
@@ -366,7 +231,7 @@ public class SubjectTest extends TestCase {
366231 } catch (Exception e) {
367232 fail(e + " was thrown instead of NullPointerException");
368233 }
369-
234+
370235 try {
371236 Subject.doAsPrivileged(subj, new PrivilegedExceptionAction<Object>(){
372237 public Object run() throws PrivilegedActionException {
@@ -376,220 +241,8 @@ public class SubjectTest extends TestCase {
376241 fail("PrivilegedActionException wasn't thrown");
377242 } catch (PrivilegedActionException e) {
378243 }
379-
380- class TestSecurityManager extends SecurityManager {
381- @Override
382- public void checkPermission(Permission permission) {
383- if (permission instanceof AuthPermission
384- && "doAsPrivileged".equals(permission.getName())) {
385- throw new SecurityException();
386- }
387- super.checkPermission(permission);
388- }
389- }
390- TestSecurityManager s = new TestSecurityManager();
391- System.setSecurityManager(s);
392- try {
393- Object obj = Subject.doAsPrivileged(subj, pea, acc);
394- fail("SecurityException wasn't thrown");
395- } catch (SecurityException se) {
396- } catch (Exception e) {
397- fail(e + " was thrown instead of SecurityException");
398- }
399- }
400-
401- /**
402- * @tests javax.security.auth.Subject#equals(Object o)
403- */
404- @TestTargetNew(
405- level = TestLevel.SUFFICIENT,
406- notes = "SecurityException wasn't tested",
407- method = "equals",
408- args = {Object.class}
409- )
410- public void test_equals() {
411- Set <Principal> principal = new HashSet<Principal>();
412- Set <Principal> principal1 = new HashSet<Principal>();
413- Set <Object> pubCredentials = new HashSet<Object>();
414- Set <Object> privCredentials = new HashSet<Object>();
415- Principal pr1 = new PrincipalImpl("TestPrincipal1");
416- Principal pr2 = new PrincipalImpl("TestPrincipal2");
417- principal.add(pr1);
418- principal.add(pr2);
419- principal1.add(pr1);
420- Object pubCredential1 = new Object();
421- Object pubCredential2 = new Object();
422- pubCredentials.add(pubCredential1);
423- pubCredentials.add(pubCredential2);
424- Object privCredential1 = new Object();
425- Object privCredential2 = new Object();
426- privCredentials.add(privCredential1);
427- privCredentials.add(privCredential2);
428-
429- Subject s1 = new Subject(true, principal, pubCredentials, privCredentials);
430- Subject s2 = new Subject(true, principal1, pubCredentials, privCredentials);
431- Subject s3 = new Subject(true, principal, pubCredentials, privCredentials);
432-
433- try {
434- assertTrue(s1.equals(s1));
435- assertFalse(s1.equals(s2));
436- assertTrue(s1.equals(s3));
437- assertFalse(s1.equals(new Object()));
438- } catch (Exception e) {
439- fail("Unexpected exception: " + e);
440- }
441-
442-
443- class TestSecurityManager extends SecurityManager {
444- @Override
445- public void checkPermission(Permission permission) {
446- if (permission instanceof PrivateCredentialPermission
447- && "equals".equals(permission.getName())) {
448- throw new SecurityException();
449- }
450- super.checkPermission(permission);
451- }
452- }
453- TestSecurityManager s = new TestSecurityManager();
454- System.setSecurityManager(s);
455- try {
456- s1.equals(s1);
457- //fail("SecurityException wasn't thrown");
458- } catch (SecurityException se) {
459- }
460- }
461-
462- /**
463- * @tests javax.security.auth.Subject#getPrincipals()
464- * @tests javax.security.auth.Subject#getPrivateCredentials()
465- * @tests javax.security.auth.Subject#getPublicCredentials()
466- * @tests javax.security.auth.Subject#isReadOnly()
467- * @tests javax.security.auth.Subject#setReadOnly()
468- */
469- @TestTargets({
470- @TestTargetNew(
471- level = TestLevel.COMPLETE,
472- notes = "",
473- method = "getPrincipals",
474- args = {}
475- ),
476- @TestTargetNew(
477- level = TestLevel.COMPLETE,
478- notes = "",
479- method = "getPrivateCredentials",
480- args = {}
481- ),
482- @TestTargetNew(
483- level = TestLevel.COMPLETE,
484- notes = "",
485- method = "getPublicCredentials",
486- args = {}
487- )
488- })
489- public void test_getPrincipals() {
490- Set <Principal> principal = new HashSet<Principal>();
491- Set <Object> pubCredentials = new HashSet<Object>();
492- Set <Object> privCredentials = new HashSet<Object>();
493- Principal pr1 = new PrincipalImpl("TestPrincipal1");
494- Principal pr2 = new PrincipalImpl("TestPrincipal2");
495- principal.add(pr1);
496- principal.add(pr2);
497- Object pubCredential1 = new Object();
498- pubCredentials.add(pubCredential1);
499- Object privCredential1 = new Object();
500- Object privCredential2 = new Object();
501- privCredentials.add(privCredential1);
502- privCredentials.add(privCredential2);
503-
504- Subject s = new Subject(false, principal, pubCredentials, privCredentials);
505-
506- try {
507- Set<Principal> pr = s.getPrincipals();
508- assertNotNull(pr);
509- assertEquals(principal.size(), pr.size());
510- } catch (Exception e) {
511- fail("Unexpected exception: " + e);
512- }
513-
514- try {
515- Set<Object> privC = s.getPrivateCredentials();
516- assertNotNull(privC);
517- assertEquals(privCredentials.size(), privC.size());
518- } catch (Exception e) {
519- fail("Unexpected exception: " + e);
520- }
521-
522- try {
523- Set<Object> pubC = s.getPublicCredentials();
524- assertNotNull(pubC);
525- assertEquals(pubCredentials.size(), pubC.size());
526- } catch (Exception e) {
527- fail("Unexpected exception: " + e);
528- }
529- }
530-
531- /**
532- * @tests javax.security.auth.Subject#isReadOnly()
533- * @tests javax.security.auth.Subject#setReadOnly()
534- */
535- @TestTargets({
536- @TestTargetNew(
537- level = TestLevel.COMPLETE,
538- notes = "",
539- method = "isReadOnly",
540- args = {}
541- ),
542- @TestTargetNew(
543- level = TestLevel.COMPLETE,
544- notes = "",
545- method = "setReadOnly",
546- args = {}
547- )
548- })
549- public void test_ReadOnly() {
550- Set <Principal> principal = new HashSet<Principal>();
551- Set <Object> pubCredentials = new HashSet<Object>();
552- Set <Object> privCredentials = new HashSet<Object>();
553- Principal pr1 = new PrincipalImpl("TestPrincipal1");
554- Principal pr2 = new PrincipalImpl("TestPrincipal2");
555- principal.add(pr1);
556- principal.add(pr2);
557- Object pubCredential1 = new Object();
558- pubCredentials.add(pubCredential1);
559- Object privCredential1 = new Object();
560- Object privCredential2 = new Object();
561- privCredentials.add(privCredential1);
562- privCredentials.add(privCredential2);
563-
564- Subject s = new Subject(false, principal, pubCredentials, privCredentials);
565-
566- try {
567- assertFalse(s.isReadOnly());
568- s.setReadOnly();
569- assertTrue(s.isReadOnly());
570- } catch (Exception e) {
571- fail("Unexpected exception " + e);
572- }
573-
574- class TestSecurityManager extends SecurityManager {
575- @Override
576- public void checkPermission(Permission permission) {
577- if (permission instanceof AuthPermission
578- && "setReadOnly".equals(permission.getName())) {
579- throw new SecurityException();
580- }
581- super.checkPermission(permission);
582- }
583- }
584- TestSecurityManager ss = new TestSecurityManager();
585- System.setSecurityManager(ss);
586- try {
587- s.setReadOnly();
588- fail("SecurityException wasn't thrown");
589- } catch (SecurityException se) {
590- }
591244 }
592-
245+
593246 /**
594247 * @tests javax.security.auth.Subject#getSubject(AccessControlContext acc)
595248 */
@@ -602,32 +255,14 @@ public class SubjectTest extends TestCase {
602255 public void test_getSubject() {
603256 Subject subj = new Subject();
604257 AccessControlContext acc = new AccessControlContext(new ProtectionDomain[0]);
605-
258+
606259 try {
607260 assertNull(Subject.getSubject(acc));
608261 } catch (Exception e) {
609262 fail("Unexpected exception " + e);
610263 }
611-
612- class TestSecurityManager extends SecurityManager {
613- @Override
614- public void checkPermission(Permission permission) {
615- if (permission instanceof AuthPermission
616- && "getSubject".equals(permission.getName())) {
617- throw new SecurityException();
618- }
619- super.checkPermission(permission);
620- }
621- }
622- TestSecurityManager s = new TestSecurityManager();
623- System.setSecurityManager(s);
624- try {
625- Subject.getSubject(acc);
626- fail("SecurityException wasn't thrown");
627- } catch (SecurityException se) {
628- }
629264 }
630-
265+
631266 /**
632267 * @tests javax.security.auth.Subject#toString()
633268 */
@@ -639,14 +274,14 @@ public class SubjectTest extends TestCase {
639274 )
640275 public void test_toString() {
641276 Subject subj = new Subject();
642-
277+
643278 try {
644279 assertNotNull("Null returned", subj.toString());
645280 } catch (Exception e) {
646281 fail("Unexpected exception: " + e);
647282 }
648283 }
649-
284+
650285 /**
651286 * @tests javax.security.auth.Subject#hashCode()
652287 */
@@ -658,115 +293,12 @@ public class SubjectTest extends TestCase {
658293 )
659294 public void test_hashCode() {
660295 Subject subj = new Subject();
661-
296+
662297 try {
663298 assertNotNull("Null returned", subj.hashCode());
664299 } catch (Exception e) {
665300 fail("Unexpected exception: " + e);
666301 }
667-
668- class TestSecurityManager extends SecurityManager {
669- @Override
670- public void checkPermission(Permission permission) {
671- if (permission instanceof AuthPermission
672- && "hashCode".equals(permission.getName())) {
673- throw new SecurityException();
674- }
675- super.checkPermission(permission);
676- }
677- }
678- TestSecurityManager s = new TestSecurityManager();
679- System.setSecurityManager(s);
680- try {
681- subj.hashCode();
682- //fail("SecurityException wasn't thrown");
683- } catch (SecurityException se) {
684- }
685- }
686-
687- /**
688- * @tests javax.security.auth.Subject#getPrincipals(Class<T> c)
689- * @tests javax.security.auth.Subject#getPrivateCredentials(Class<T> c)
690- * @tests javax.security.auth.Subject#getPublicCredentials(Class<T> c)
691- */
692- @TestTargets({
693- @TestTargetNew(
694- level = TestLevel.COMPLETE,
695- notes = "",
696- method = "getPrincipals",
697- args = {Class.class}
698- ),
699- @TestTargetNew(
700- level = TestLevel.SUFFICIENT,
701- notes = "",
702- method = "getPrivateCredentials",
703- args = {Class.class}
704- ),
705- @TestTargetNew(
706- level = TestLevel.SUFFICIENT,
707- notes = "",
708- method = "getPublicCredentials",
709- args = {Class.class}
710- )
711- })
712- public void test_getPrincipals_Class() {
713- Set <Principal> principal = new HashSet<Principal>();
714- Set <Object> pubCredentials = new HashSet<Object>();
715- Set <Object> privCredentials = new HashSet<Object>();
716- Principal pr1 = new PrincipalImpl("TestPrincipal1");
717- Principal pr2 = new PrincipalImpl("TestPrincipal2");
718- principal.add(pr1);
719- principal.add(pr2);
720- Object pubCredential1 = new Object();
721- pubCredentials.add(pubCredential1);
722- Object privCredential1 = new Object();
723- Object privCredential2 = new Object();
724- privCredentials.add(privCredential1);
725- privCredentials.add(privCredential2);
726-
727- Subject s = new Subject(true, principal, pubCredentials, privCredentials);
728-
729- try {
730- Set<Principal> pr = s.getPrincipals(null);
731- fail("NullPointerException wasn't thrown");
732- } catch (NullPointerException npe) {
733- }
734-
735- try {
736- Set<Object> privC = s.getPrivateCredentials(null);
737- fail("NullPointerException wasn't thrown");
738- } catch (NullPointerException npe) {
739- }
740-
741- try {
742- Set<Object> pubC = s.getPublicCredentials(null);
743- fail("NullPointerException wasn't thrown");
744- } catch (NullPointerException npe) {
745- }
746-
747- try {
748- Set<Principal> pr = s.getPrincipals(Principal.class);
749- assertNotNull(pr);
750- assertEquals(principal.size(), pr.size());
751- } catch (Exception e) {
752- fail("Unexpected exception: " + e);
753- }
754-
755- try {
756- Set<Object> privC = s.getPrivateCredentials(Object.class);
757- assertNotNull(privC);
758- assertEquals(privCredentials.size(), privC.size());
759- } catch (Exception e) {
760- fail("Unexpected exception: " + e);
761- }
762-
763- try {
764- Set<Object> pubC = s.getPublicCredentials(Object.class);
765- assertNotNull(pubC);
766- assertEquals(pubCredentials.size(), pubC.size());
767- } catch (Exception e) {
768- fail("Unexpected exception: " + e);
769- }
770302 }
771303 }
772304
--- a/libcore/security/src/test/java/tests/security/acl/AllTests.java
+++ b/libcore/security/src/test/java/tests/security/acl/AllTests.java
@@ -39,11 +39,6 @@ public class AllTests {
3939 suite.addTestSuite(LastOwnerExceptionTest.class);
4040 suite.addTestSuite(NotOwnerException2Test.class);
4141 suite.addTestSuite(NotOwnerExceptionTest.class);
42- suite.addTestSuite(IPermissionTest.class);
43- suite.addTestSuite(IGroupTest.class);
44- suite.addTestSuite(IOwnerTest.class);
45- suite.addTestSuite(IAclEntryTest.class);
46- suite.addTestSuite(IAclTest.class);
4742
4843 // $JUnit-END$
4944 return suite;
--- a/libcore/security/src/test/java/tests/security/acl/IAclEntryTest.java
+++ /dev/null
@@ -1,213 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.acl;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.acl.AclEntry;
28-import java.security.acl.Permission;
29-import java.security.Principal;
30-import java.util.Enumeration;
31-import java.util.Vector;
32-
33-import org.apache.harmony.security.tests.support.acl.*;
34-
35-@TestTargetClass(AclEntry.class)
36-public class IAclEntryTest extends TestCase {
37-
38- class MyAclEntry extends AclEntryImpl {
39- public MyAclEntry() {
40- super();
41- }
42- public MyAclEntry(Principal pr) {
43- super(pr);
44- }
45- }
46-
47-
48- /**
49- * @tests java.security.acl.AclEntry#addPermission(Permission permission)
50- * @tests java.security.acl.AclEntry#checkPermission(Permission permission)
51- * @tests java.security.acl.AclEntry#removePermission(Permission permission)
52- */
53- @TestTargets({
54- @TestTargetNew(
55- level = TestLevel.COMPLETE,
56- notes = "",
57- method = "addPermission",
58- args = {java.security.acl.Permission.class}
59- ),
60- @TestTargetNew(
61- level = TestLevel.COMPLETE,
62- notes = "",
63- method = "checkPermission",
64- args = {java.security.acl.Permission.class}
65- ),
66- @TestTargetNew(
67- level = TestLevel.COMPLETE,
68- notes = "",
69- method = "removePermission",
70- args = {java.security.acl.Permission.class}
71- )
72- })
73- public void test_AclEntry01() {
74- Permission perm = new PermissionImpl("Permission_1");
75- MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
76- try {
77- assertTrue(ae.addPermission(perm));
78- assertFalse(ae.addPermission(perm));
79- assertTrue(ae.checkPermission(perm));
80- assertTrue(ae.removePermission(perm));
81- assertFalse(ae.removePermission(perm));
82- assertFalse(ae.checkPermission(perm));
83- } catch (Exception ex) {
84- fail("Unexpected exception " + ex);
85- }
86- }
87-
88- /**
89- * @tests java.security.acl.AclEntry#getPrincipal()
90- * @tests java.security.acl.AclEntry#setPrincipal(Principal user)
91- */
92- @TestTargets({
93- @TestTargetNew(
94- level = TestLevel.COMPLETE,
95- notes = "",
96- method = "getPrincipal",
97- args = {}
98- ),
99- @TestTargetNew(
100- level = TestLevel.COMPLETE,
101- notes = "",
102- method = "setPrincipal",
103- args = {java.security.Principal.class}
104- )
105- })
106- public void test_AclEntry02() {
107- MyAclEntry ae = new MyAclEntry();
108- Principal mp = new PrincipalImpl("TestPrincipal");
109- try {
110- assertTrue(ae.setPrincipal(mp));
111- Principal p = ae.getPrincipal();
112- assertEquals("Names are not equal", p.getName(), mp.getName());
113- assertFalse(ae.setPrincipal(mp));
114- } catch (Exception ex) {
115- fail("Unexpected exception " + ex);
116- }
117- }
118-
119- /**
120- * @tests java.security.acl.AclEntry#setNegativePermissions()
121- * @tests java.security.acl.AclEntry#isNegative()
122- */
123- @TestTargets({
124- @TestTargetNew(
125- level = TestLevel.COMPLETE,
126- notes = "",
127- method = "setNegativePermissions",
128- args = {}
129- ),
130- @TestTargetNew(
131- level = TestLevel.COMPLETE,
132- notes = "",
133- method = "isNegative",
134- args = {}
135- )
136- })
137- public void test_AclEntry03() {
138- MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
139- try {
140- assertFalse("isNegative() returns TRUE",ae.isNegative());
141- ae.setNegativePermissions();
142- assertTrue("isNegative() returns FALSE", ae.isNegative());
143- } catch (Exception ex) {
144- fail("Unexpected exception " + ex);
145- }
146- }
147-
148- /**
149- * @tests java.security.acl.AclEntry#permissions()
150- */
151- @TestTargetNew(
152- level = TestLevel.COMPLETE,
153- notes = "",
154- method = "permissions",
155- args = {}
156- )
157- public void test_AclEntry04() {
158- MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
159- Permission perm = new PermissionImpl("Permission_1");
160- try {
161- Enumeration en = ae.permissions();
162- assertFalse("Not empty enumeration", en.hasMoreElements());
163- ae.addPermission(perm);
164- en = ae.permissions();
165- assertTrue("Eempty enumeration", en.hasMoreElements());
166- Vector v = new Vector();
167- while (en.hasMoreElements()) {
168- v.addElement(en.nextElement());
169- }
170- assertEquals(v.size(), 1);
171- assertEquals(v.elementAt(0).toString(), perm.toString());
172- } catch (Exception ex) {
173- fail("Unexpected exception " + ex);
174- }
175- }
176-
177- /**
178- * @tests java.security.acl.AclEntry#toString()
179- */
180- @TestTargetNew(
181- level = TestLevel.COMPLETE,
182- notes = "",
183- method = "toString",
184- args = {}
185- )
186- public void test_AclEntry05() {
187- MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
188- try {
189- String res = ae.toString();
190- assertTrue(res.contains("TestPrincipal"));
191- } catch (Exception ex) {
192- fail("Unexpected exception " + ex);
193- }
194- }
195-
196- /**
197- * @tests java.security.acl.AclEntry#clone()
198- */
199- @TestTargetNew(
200- level = TestLevel.COMPLETE,
201- notes = "",
202- method = "clone",
203- args = {}
204- )
205- public void test_AclEntry06() {
206- MyAclEntry ae = new MyAclEntry(new PrincipalImpl("TestPrincipal"));
207- try {
208- assertEquals("Objects are not equal", ae.toString(), ae.clone().toString());
209- } catch (Exception ex) {
210- fail("Unexpected exception " + ex);
211- }
212- }
213-}
\ No newline at end of file
--- a/libcore/security/src/test/java/tests/security/acl/IAclTest.java
+++ /dev/null
@@ -1,230 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.acl;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.acl.Acl;
28-import java.security.acl.AclEntry;
29-import java.security.acl.NotOwnerException;
30-import java.security.acl.Permission;
31-import java.security.Principal;
32-import java.util.Enumeration;
33-import java.util.Vector;
34-
35-import org.apache.harmony.security.tests.support.acl.*;
36-
37-@TestTargetClass(Acl.class)
38-public class IAclTest extends TestCase {
39-
40- class MyAcl extends AclImpl {
41- public MyAcl(Principal principal, String str) {
42- super(principal, str);
43- }
44- }
45-
46-
47- /**
48- * @tests java.security.acl.Acl#addEntry(Principal caller, AclEntry entry)
49- * @tests java.security.acl.Acl#removeEntry(Principal caller, AclEntry entry)
50- */
51- @TestTargets({
52- @TestTargetNew(
53- level = TestLevel.COMPLETE,
54- notes = "",
55- method = "addEntry",
56- args = {java.security.Principal.class, java.security.acl.AclEntry.class}
57- ),
58- @TestTargetNew(
59- level = TestLevel.COMPLETE,
60- notes = "",
61- method = "removeEntry",
62- args = {java.security.Principal.class, java.security.acl.AclEntry.class}
63- )
64- })
65- public void test_Acl01() {
66- Principal pr = new PrincipalImpl("TestPrincipal");
67- String str = "TestName";
68- MyAcl acl = new MyAcl(pr, str);
69- AclEntry ae = new AclEntryImpl(pr);
70- try {
71- assertTrue(acl.addEntry(pr, ae));
72- assertFalse(acl.addEntry(pr, ae));
73- assertTrue(acl.removeEntry(pr, ae));
74- assertFalse(acl.removeEntry(pr, ae));
75- } catch (Exception ex) {
76- fail("Unexpected exception " + ex);
77- }
78-
79- try {
80- acl.addEntry(new PrincipalImpl("NewPrincipal"), ae);
81- fail("NotOwnerException was not thrown");
82- } catch (NotOwnerException noe) {
83- //expected
84- }
85-
86- try {
87- acl.removeEntry(new PrincipalImpl("NewPrincipal"), ae);
88- fail("NotOwnerException was not thrown");
89- } catch (NotOwnerException noe) {
90- //expected
91- }
92- }
93-
94- /**
95- * @tests java.security.acl.Acl#setName(Principal caller, String name)
96- * @tests java.security.acl.Acl#getName()
97- */
98- @TestTargets({
99- @TestTargetNew(
100- level = TestLevel.COMPLETE,
101- notes = "",
102- method = "setName",
103- args = {java.security.Principal.class, java.lang.String.class}
104- ),
105- @TestTargetNew(
106- level = TestLevel.COMPLETE,
107- notes = "",
108- method = "getName",
109- args = {}
110- )
111- })
112- public void test_Acl02() {
113- Principal pr = new PrincipalImpl("TestPrincipal");
114- String str = "TestName";
115- String newStr = "NewName";
116- MyAcl acl = new MyAcl(pr, str);
117- try {
118- assertEquals("Names are not equal", str, acl.getName());
119- acl.setName(pr, newStr);
120- assertEquals("Names are not equal", newStr, acl.getName());
121- } catch (Exception ex) {
122- fail("Unexpected exception " + ex);
123- }
124-
125- try {
126- acl.setName(new PrincipalImpl("NewPrincipal"), str);
127- fail("NotOwnerException was not thrown");
128- } catch (NotOwnerException noe) {
129- //expected
130- }
131- }
132-
133- /**
134- * @tests java.security.acl.Acl#toString()
135- */
136- @TestTargetNew(
137- level = TestLevel.COMPLETE,
138- notes = "",
139- method = "toString",
140- args = {}
141- )
142- public void test_Acl03() {
143- Principal pr = new PrincipalImpl("TestPrincipal");
144- String str = "TestName";
145- MyAcl acl = new MyAcl(pr, str);
146- AclEntry ae = new AclEntryImpl(pr);
147- Permission perm = new PermissionImpl("Permission_1");
148- try {
149- ae.addPermission(perm);
150- acl.addEntry(pr, ae);
151- String res = acl.toString();
152- assertTrue(res.contains(perm.toString()));
153- } catch (Exception ex) {
154- fail("Unexpected exception " + ex);
155- }
156- }
157-
158- /**
159- * @tests java.security.acl.Acl#entries()
160- */
161- @TestTargetNew(
162- level = TestLevel.COMPLETE,
163- notes = "",
164- method = "entries",
165- args = {}
166- )
167- public void test_Acl04() {
168- Principal pr = new PrincipalImpl("TestPrincipal");
169- String str = "TestName";
170- MyAcl acl = new MyAcl(pr, str);
171- AclEntry ae1 = new AclEntryImpl(pr);
172- try {
173- ae1.addPermission(new PermissionImpl("Permission_1"));
174- acl.addEntry(pr, ae1);
175- Enumeration en = acl.entries();
176- Vector v = new Vector();
177- while (en.hasMoreElements()) {
178- v.addElement(en.nextElement());
179- }
180- assertEquals(v.size(), 1);
181- } catch (Exception ex) {
182- fail("Unexpected exception " + ex);
183- }
184- }
185-
186- /**
187- * @tests java.security.acl.Acl#checkPermission(Principal principal, Permission permission)
188- * @tests java.security.acl.Acl#getPermissions(Principal principal)
189- */
190- @TestTargets({
191- @TestTargetNew(
192- level = TestLevel.COMPLETE,
193- notes = "",
194- method = "checkPermission",
195- args = {java.security.Principal.class, java.security.acl.Permission.class}
196- ),
197- @TestTargetNew(
198- level = TestLevel.COMPLETE,
199- notes = "",
200- method = "getPermissions",
201- args = {java.security.Principal.class}
202- )
203- })
204- public void test_Acl05() {
205- Principal pr = new PrincipalImpl("TestPrincipal");
206- String str = "TestName";
207- MyAcl acl = new MyAcl(pr, str);
208- AclEntry ae = new AclEntryImpl(pr);
209- Permission perm = new PermissionImpl("Permission_1");
210- try {
211- ae.addPermission(perm);
212- acl.addEntry(pr, ae);
213-
214- //checkPermission verification
215- assertTrue("Incorrect permission", acl.checkPermission(pr, perm));
216- assertFalse(acl.checkPermission(pr, new PermissionImpl("Permission_2")));
217-
218- //getPermissions
219- Enumeration en = acl.getPermissions(pr);
220- Vector v = new Vector();
221- while (en.hasMoreElements()) {
222- v.addElement(en.nextElement());
223- }
224- assertEquals(v.size(), 1);
225- assertEquals(v.elementAt(0).toString(), perm.toString());
226- } catch (Exception ex) {
227- fail("Exception " + ex + " was thrown");
228- }
229- }
230-}
\ No newline at end of file
--- a/libcore/security/src/test/java/tests/security/acl/IGroupTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.acl;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.acl.Group;
28-import java.security.Principal;
29-import java.util.Enumeration;
30-
31-import org.apache.harmony.security.tests.support.acl.*;
32-
33-@TestTargetClass(Group.class)
34-public class IGroupTest extends TestCase {
35-
36- class MyGroup extends GroupImpl {
37- public MyGroup(String str) {
38- super(str);
39- }
40- }
41-
42- /**
43- * @tests java.security.acl.Group#addMember(Principal user)
44- */
45- @TestTargets({
46- @TestTargetNew(
47- level = TestLevel.COMPLETE,
48- notes = "",
49- method = "addMember",
50- args = {java.security.Principal.class}
51- ),
52- @TestTargetNew(
53- level = TestLevel.COMPLETE,
54- notes = "",
55- method = "isMember",
56- args = {java.security.Principal.class}
57- ),
58- @TestTargetNew(
59- level = TestLevel.COMPLETE,
60- notes = "",
61- method = "removeMember",
62- args = {java.security.Principal.class}
63- )
64- })
65- public void test_addMember() {
66- MyGroup gr = new MyGroup("TestOwners");
67- Principal pr = new PrincipalImpl("TestPrincipal");
68- try {
69- assertTrue(gr.addMember(pr));
70- assertFalse(gr.addMember(pr));
71- assertTrue(gr.isMember(pr));
72- assertTrue(gr.removeMember(pr));
73- assertFalse(gr.isMember(pr));
74- assertFalse(gr.removeMember(pr));
75- } catch (Exception e) {
76- fail("Unexpected exception " + e);
77- }
78- }
79-
80- /**
81- * @tests java.security.acl.Group#members()
82- */
83- @TestTargetNew(
84- level = TestLevel.COMPLETE,
85- notes = "",
86- method = "members",
87- args = {}
88- )
89- public void test_members() {
90- MyGroup gr = new MyGroup("TestOwners");
91- Principal pr = new PrincipalImpl("TestPrincipal");
92- try {
93- Enumeration en = gr.members();
94- assertFalse("Not empty enumeration", en.hasMoreElements());
95- assertTrue(gr.addMember(pr));
96- assertTrue("Empty enumeration", en.hasMoreElements());
97- } catch (Exception e) {
98- fail("Unexpected exception " + e);
99- }
100- }
101-}
\ No newline at end of file
--- a/libcore/security/src/test/java/tests/security/acl/IOwnerTest.java
+++ /dev/null
@@ -1,148 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.acl;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.acl.Owner;
28-import java.security.Principal;
29-import java.security.acl.NotOwnerException;
30-import java.security.acl.LastOwnerException;
31-
32-import org.apache.harmony.security.tests.support.acl.*;
33-
34-@TestTargetClass(Owner.class)
35-public class IOwnerTest extends TestCase {
36-
37- class MyOwner extends OwnerImpl {
38- public MyOwner(Principal pr) {
39- super(pr);
40- }
41- }
42-
43- /**
44- * @tests java.security.acl.Owner#isOwner(Principal owner)
45- *
46- */
47- @TestTargetNew(
48- level = TestLevel.COMPLETE,
49- notes = "",
50- method = "isOwner",
51- args = {java.security.Principal.class}
52- )
53- public void test_isOwner() {
54- MyOwner mo = new MyOwner(new PrincipalImpl("NewOwner"));
55- try {
56- assertFalse("Method returns TRUE", mo.isOwner(new PrincipalImpl("TestOwner")));
57- assertTrue("Method returns FALSE", mo.isOwner(new PrincipalImpl("NewOwner")));
58- } catch (Exception ex) {
59- fail("Unexpected exception " + ex);
60- }
61- }
62-
63- /**
64- * @tests java.security.acl.Owner#addOwner(Principal caller, Principal owner)
65- *
66- */
67- @TestTargetNew(
68- level = TestLevel.COMPLETE,
69- notes = "",
70- method = "addOwner",
71- args = {java.security.Principal.class, java.security.Principal.class}
72- )
73- public void test_addOwner() {
74- Principal p1 = new PrincipalImpl("Owner");
75- Principal p2 = new PrincipalImpl("AclOwner");
76- Principal pt = new PrincipalImpl("NewOwner");
77- MyOwner mo = new MyOwner(p1);
78- try {
79- //add new owner - TRUE expected
80- assertTrue("Method returns FALSE", mo.addOwner(p1, pt));
81- //add existent owner - FALSE expected
82- assertFalse("Method returns TRUE", mo.addOwner(p1, pt));
83- } catch (Exception ex) {
84- fail("Unexpected exception " + ex);
85- }
86- //exception case
87- try {
88- mo.addOwner(p2, pt);
89- fail("NotOwnerException was not thrown");
90- } catch (NotOwnerException noe) {
91- //expected
92- }
93- }
94-
95- /**
96- * @tests java.security.acl.Owner#deleteOwner(Principal caller, Principal owner)
97- *
98- */
99- @TestTargetNew(
100- level = TestLevel.COMPLETE,
101- notes = "",
102- method = "deleteOwner",
103- args = {java.security.Principal.class, java.security.Principal.class}
104- )
105- public void test_deleteOwner() {
106- Principal caller = new PrincipalImpl("Owner");
107- Principal owner1 = new PrincipalImpl("NewOwner1");
108- Principal owner2 = new PrincipalImpl("NewOwner2");
109- Principal notCaller = new PrincipalImpl("AclOwner");
110- MyOwner mo = new MyOwner(caller);
111-
112- try {
113- if (!mo.isOwner(owner1)) mo.addOwner(caller, owner1);
114- if (!mo.isOwner(owner2)) mo.addOwner(caller, owner2);
115- } catch (Exception e) {
116- fail("Unexpected exception " + e + " was thrown for addOwner");
117- }
118-
119- try {
120- //remove existent owner - TRUE expected
121- assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner1));
122- assertFalse("Object presents in the owner list", mo.isOwner(owner1));
123- //remove owner which is not part of the list of owners - FALSE expected
124- assertFalse("Method returns TRUE", mo.deleteOwner(caller, owner1));
125- assertTrue("Method returns FALSE", mo.deleteOwner(caller, owner2));
126- } catch (Exception ex) {
127- fail("Unexpected exception " + ex);
128- }
129- //exception case - NotOwnerException
130- try {
131- mo.deleteOwner(notCaller, owner1);
132- fail("NotOwnerException was not thrown");
133- } catch (NotOwnerException noe) {
134- //expected
135- } catch (Exception e) {
136- fail(e + " was thrown instead of NotOwnerException");
137- }
138- //exception case - LastOwnerException
139- try {
140- mo.deleteOwner(caller, owner2);
141- fail("LastOwnerException was not thrown");
142- } catch (LastOwnerException loe) {
143- //expected
144- } catch (Exception e) {
145- fail(e + " was thrown instead of LastOwnerException");
146- }
147- }
148-}
\ No newline at end of file
--- a/libcore/security/src/test/java/tests/security/acl/IPermissionTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.acl;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.acl.Permission;
28-
29-import org.apache.harmony.security.tests.support.acl.*;
30-
31-@TestTargetClass(Permission.class)
32-public class IPermissionTest extends TestCase {
33-
34- class MyPermission extends PermissionImpl {
35- public MyPermission(String str) {
36- super(str);
37- }
38- }
39-
40- /**
41- * @tests java.security.acl.Permission#equals(Object another)
42- */
43- @TestTargetNew(
44- level = TestLevel.COMPLETE,
45- notes = "",
46- method = "equals",
47- args = {java.lang.Object.class}
48- )
49- public void test_equals() {
50- try {
51- MyPermission mp1 = new MyPermission("TestPermission");
52- MyPermission mp2 = new MyPermission("NewTestPermission");
53- Object another = new Object();
54- assertFalse(mp1.equals(another));
55- assertFalse(mp1.equals(mp2));
56- assertTrue(mp1.equals(new MyPermission("TestPermission")));
57- } catch (Exception e) {
58- fail("Unexpected exception - subtest1");
59- }
60- }
61-
62- /**
63- * @tests java.security.acl.Permission#toString()
64- */
65- @TestTargetNew(
66- level = TestLevel.COMPLETE,
67- notes = "",
68- method = "toString",
69- args = {}
70- )
71- public void test_toString() {
72- try {
73- MyPermission obj = new MyPermission("TestPermission");
74- String res = obj.toString();
75- assertEquals(res, "TestPermission");
76- } catch (Exception e) {
77- fail("Unexpected exception - subtest2");
78- }
79- }
80-}
\ No newline at end of file
--- a/libcore/security/src/test/java/tests/security/cert/AllTests.java
+++ b/libcore/security/src/test/java/tests/security/cert/AllTests.java
@@ -80,7 +80,6 @@ public class AllTests {
8080 // Crashes on RI.
8181 // suite.addTestSuite(X509CertSelectorTest.class);
8282 suite.addTestSuite(X509Certificate2Test.class);
83- suite.addTestSuite(PolicyNodeTest.class);
8483
8584 // $JUnit-END$
8685 return suite;
--- a/libcore/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java
+++ b/libcore/security/src/test/java/tests/security/cert/CollectionCertStoreParametersTest.java
@@ -36,9 +36,9 @@ import java.util.Collection;
3636 import java.util.Vector;
3737
3838 import org.apache.harmony.security.tests.support.cert.MyCertificate;
39+
3940 /**
40- * Tests for <code>CollectionCertStoreParameters</code>
41- *
41+ * Tests for <code>CollectionCertStoreParameters</code>.
4242 */
4343 @TestTargetClass(CollectionCertStoreParameters.class)
4444 public class CollectionCertStoreParametersTest extends TestCase {
@@ -49,8 +49,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
4949
5050 /**
5151 * Test #1 for <code>CollectionCertStoreParameters()</code> constructor<br>
52- * Assertion: Creates an instance of CollectionCertStoreParameters
53- * with the default parameter values (an empty and immutable Collection)
5452 */
5553 @TestTargetNew(
5654 level = TestLevel.PARTIAL_COMPLETE,
@@ -66,8 +64,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
6664
6765 /**
6866 * Test #2 for <code>CollectionCertStoreParameters</code> constructor<br>
69- * Assertion: Creates an instance of CollectionCertStoreParameters
70- * with the default parameter values (an empty and immutable Collection)
7167 */
7268 @TestTargetNew(
7369 level = TestLevel.PARTIAL_COMPLETE,
@@ -93,7 +89,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
9389 /**
9490 * Test #1 for <code>CollectionCertStoreParameters(Collection)</code>
9591 * constructor<br>
96- * Assertion: Creates an instance of CollectionCertStoreParameters
9792 */
9893 @TestTargetNew(
9994 level = TestLevel.PARTIAL_COMPLETE,
@@ -110,9 +105,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
110105 /**
111106 * Test #2 for <code>CollectionCertStoreParameters(Collection)</code>
112107 * constructor<br>
113- * Assertion: If the specified <code>Collection</code> contains an object
114- * that is not a <code>Certificate</code> or <code>CRL</code>, that object
115- * will be ignored by the Collection <code>CertStore</code>.
116108 */
117109 @TestTargetNew(
118110 level = TestLevel.PARTIAL_COMPLETE,
@@ -132,11 +124,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
132124 /**
133125 * Test #3 for <code>CollectionCertStoreParameters(Collection)</code>
134126 * constructor<br>
135- * Assertion: The Collection is not copied. Instead, a reference is used.
136- * This allows the caller to subsequently add or remove Certificates or
137- * CRLs from the Collection, thus changing the set of Certificates or CRLs
138- * available to the Collection CertStore. The Collection CertStore will
139- * not modify the contents of the Collection
140127 */
141128 @TestTargetNew(
142129 level = TestLevel.PARTIAL_COMPLETE,
@@ -149,7 +136,7 @@ public class CollectionCertStoreParametersTest extends TestCase {
149136 // create using empty collection
150137 CollectionCertStoreParameters cp =
151138 new CollectionCertStoreParameters(certificates);
152- // check that the reference is used
139+ // check that the reference is used
153140 assertTrue("isRefUsed_1", certificates == cp.getCollection());
154141 // check that collection still empty
155142 assertTrue("isEmpty", cp.getCollection().isEmpty());
@@ -163,8 +150,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
163150 /**
164151 * Test #4 for <code>CollectionCertStoreParameters(Collection)</code>
165152 * constructor<br>
166- * Assertion: <code>NullPointerException</code> - if
167- * <code>collection</code> is <code>null</code>
168153 */
169154 @TestTargetNew(
170155 level = TestLevel.PARTIAL_COMPLETE,
@@ -182,7 +167,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
182167
183168 /**
184169 * Test #1 for <code>clone()</code> method<br>
185- * Assertion: Returns a copy of this object
186170 */
187171 @TestTargetNew(
188172 level = TestLevel.PARTIAL_COMPLETE,
@@ -203,8 +187,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
203187
204188 /**
205189 * Test #2 for <code>clone()</code> method<br>
206- * Assertion: ...only a reference to the <code>Collection</code>
207- * is copied, and not the contents
208190 */
209191 @TestTargetNew(
210192 level = TestLevel.PARTIAL_COMPLETE,
@@ -225,8 +207,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
225207
226208 /**
227209 * Test #3 for <code>clone()</code> method<br>
228- * Assertion: ...only a reference to the <code>Collection</code>
229- * is copied, and not the contents
230210 */
231211 @TestTargetNew(
232212 level = TestLevel.PARTIAL_COMPLETE,
@@ -248,7 +228,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
248228
249229 /**
250230 * Test #1 for <code>toString()</code> method<br>
251- * Assertion: returns the formatted string describing parameters
252231 */
253232 @TestTargetNew(
254233 level = TestLevel.PARTIAL_COMPLETE,
@@ -265,7 +244,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
265244
266245 /**
267246 * Test #2 for <code>toString()</code> method<br>
268- * Assertion: returns the formatted string describing parameters
269247 */
270248 @TestTargetNew(
271249 level = TestLevel.PARTIAL_COMPLETE,
@@ -284,7 +262,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
284262
285263 /**
286264 * Test #1 for <code>getCollection()</code> method<br>
287- * Assertion: returns the Collection (never null)
288265 */
289266 @TestTargetNew(
290267 level = TestLevel.PARTIAL_COMPLETE,
@@ -299,7 +276,6 @@ public class CollectionCertStoreParametersTest extends TestCase {
299276
300277 /**
301278 * Test #2 for <code>getCollection()</code> method<br>
302- * Assertion: returns the Collection (never null)
303279 */
304280 @TestTargetNew(
305281 level = TestLevel.PARTIAL_COMPLETE,
--- a/libcore/security/src/test/java/tests/security/cert/PolicyNodeTest.java
+++ /dev/null
@@ -1,292 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package tests.security.cert;
19-
20-import dalvik.annotation.TestTargets;
21-import dalvik.annotation.TestLevel;
22-import dalvik.annotation.TestTargetNew;
23-import dalvik.annotation.TestTargetClass;
24-
25-import junit.framework.TestCase;
26-
27-import java.security.cert.PolicyNode;
28-import java.security.cert.PolicyQualifierInfo;
29-import java.util.HashSet;
30-import java.util.Set;
31-import java.util.Iterator;
32-
33-import org.apache.harmony.security.tests.support.cert.PolicyNodeImpl;
34-
35-/**
36- * Tests for <code>java.security.cert.PolicyNode</code> fields and methods
37- *
38- */
39-@TestTargetClass(PolicyNode.class)
40-public class PolicyNodeTest extends TestCase {
41-
42- private String validPolicy = "ValidPolicy";
43- private String anyPolicy = "2.5.29.32.0";
44- private boolean criticalityIndicator = true;
45- private HashSet hs = null;
46-
47- /**
48- * Returns valid DER encoding for the following ASN.1 definition
49- * (as specified in RFC 3280 -
50- * Internet X.509 Public Key Infrastructure.
51- * Certificate and Certificate Revocation List (CRL) Profile.
52- * http://www.ietf.org/rfc/rfc3280.txt):
53- *
54- * PolicyQualifierInfo ::= SEQUENCE {
55- * policyQualifierId PolicyQualifierId,
56- * qualifier ANY DEFINED BY policyQualifierId
57- * }
58- *
59- * where policyQualifierId (OID) is
60- * 1.3.6.1.5.5.7.2.1
61- * and qualifier (IA5String) is
62- * "http://www.qq.com/stmt.txt"
63- *
64- * (data generated by own encoder during test development)
65- */
66- private static final byte[] getDerEncoding() {
67- // DO NOT MODIFY!
68- return new byte[] {
69- (byte)0x30, (byte)0x26, // tag Seq, length
70- (byte)0x06, (byte)0x08, // tag OID, length
71- (byte)0x2b, (byte)0x06, (byte)0x01, (byte)0x05, // oid value
72- (byte)0x05, (byte)0x07, (byte)0x02, (byte)0x01, // oid value
73- (byte)0x16, (byte)0x1a, // tag IA5String, length
74- (byte)0x68, (byte)0x74, (byte)0x74, (byte)0x70, // IA5String value
75- (byte)0x3a, (byte)0x2f, (byte)0x2f, (byte)0x77, // IA5String value
76- (byte)0x77, (byte)0x77, (byte)0x2e, (byte)0x71, // IA5String value
77- (byte)0x71, (byte)0x2e, (byte)0x63, (byte)0x6f, // IA5String value
78- (byte)0x6d, (byte)0x2f, (byte)0x73, (byte)0x74, // IA5String value
79- (byte)0x6d, (byte)0x74, (byte)0x2e, (byte)0x74, // IA5String value
80- (byte)0x78, (byte)0x74 // IA5String value
81- };
82- }
83-
84- protected void setUp() {
85- hs = new HashSet();
86- hs.add(new String("StringParameter1"));
87- hs.add(new String("StringParameter2"));
88- hs.add(new String("StringParameter3"));
89- }
90-
91- protected void setUp1() {
92- hs = new HashSet();
93- try {
94- hs.add(new PolicyQualifierInfo(getDerEncoding()));
95- } catch (Exception e) {
96- fail("Ezxception " + e + " for setUp1()");
97- }
98- }
99-
100-
101- class MyPolicyNode extends PolicyNodeImpl {
102- MyPolicyNode(PolicyNodeImpl policynode, String s, Set set,
103- boolean flag, Set set1, boolean flag1) {
104- super(policynode, s, set, flag, set1, flag1);
105- }
106- }
107-
108- //
109- // Tests
110- //
111-
112- /**
113- * @tests java.security.cert.PolicyNode#getDepth()
114- */
115- @TestTargetNew(
116- level = TestLevel.COMPLETE,
117- notes = "",
118- method = "getDepth",
119- args = {}
120- )
121- public final void test_getDepth() {
122- MyPolicyNode pn = new MyPolicyNode(null, validPolicy, null, criticalityIndicator, null, true);
123- try {
124- assertEquals(pn.getDepth(), 0);
125- } catch (Exception e) {
126- fail("Unexpected exception: " + e);
127- }
128- MyPolicyNode pn1 = new MyPolicyNode(pn, validPolicy, null, criticalityIndicator, null, true);
129- try {
130- assertEquals(pn1.getDepth(), 1);
131- } catch (Exception e) {
132- fail("Unexpected exception: " + e);
133- }
134- }
135-
136- /**
137- * @tests java.security.cert.PolicyNode#getValidPolicy()
138- */
139- @TestTargetNew(
140- level = TestLevel.COMPLETE,
141- notes = "",
142- method = "getValidPolicy",
143- args = {}
144- )
145- public final void test_getValidPolicy() {
146- MyPolicyNode pn = new MyPolicyNode(null, null, null, criticalityIndicator, null, true);
147- try {
148- assertEquals(pn.getValidPolicy(), "");
149- } catch (Exception e) {
150- fail("Unexpected exception: " + e);
151- }
152- pn = new MyPolicyNode(pn, validPolicy, null, criticalityIndicator, null, true);
153- try {
154- assertEquals(pn.getValidPolicy(), "ValidPolicy");
155- } catch (Exception e) {
156- fail("Unexpected exception: " + e);
157- }
158- pn = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
159- try {
160- assertEquals(pn.getValidPolicy(), "2.5.29.32.0");
161- } catch (Exception e) {
162- fail("Unexpected exception: " + e);
163- }
164- }
165-
166- /**
167- * @tests java.security.cert.PolicyNode#isCritical()
168- */
169- @TestTargetNew(
170- level = TestLevel.COMPLETE,
171- notes = "",
172- method = "isCritical",
173- args = {}
174- )
175- public final void test_isCritical() {
176- MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
177- try {
178- assertEquals(pn.isCritical(), true);
179- } catch (Exception e) {
180- fail("Unexpected exception: " + e);
181- }
182- criticalityIndicator = false;
183- pn = new MyPolicyNode(null, validPolicy, null, criticalityIndicator, null, true);
184- try {
185- assertEquals(pn.isCritical(), false);
186- } catch (Exception e) {
187- fail("Unexpected exception: " + e);
188- }
189- }
190-
191- /**
192- * @tests java.security.cert.PolicyNode#getParent()
193- */
194- @TestTargetNew(
195- level = TestLevel.COMPLETE,
196- notes = "",
197- method = "getParent",
198- args = {}
199- )
200- public final void test_getParent() {
201- MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
202- try {
203- assertNull(pn.getParent());
204- assertEquals(pn.getDepth(), 0);
205- } catch (Exception e) {
206- fail("Unexpected exception: " + e);
207- }
208- MyPolicyNode pn1 = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
209- try {
210- PolicyNode newPN = pn1.getParent();
211- assertEquals(newPN.getDepth(), 0);
212- } catch (Exception e) {
213- fail("Unexpected exception: " + e);
214- }
215- MyPolicyNode pn2 = new MyPolicyNode(pn1, anyPolicy, null, criticalityIndicator, null, true);
216- try {
217- PolicyNode newPN = pn2.getParent();
218- assertEquals(newPN.getDepth(), 1);
219- } catch (Exception e) {
220- fail("Unexpected exception: " + e);
221- }
222- }
223-
224- /**
225- * @tests java.security.cert.PolicyNode#getExpectedPolicies()
226- */
227- @TestTargetNew(
228- level = TestLevel.COMPLETE,
229- notes = "",
230- method = "getExpectedPolicies",
231- args = {}
232- )
233- public final void test_getExpectedPolicies() {
234- setUp();
235- MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, hs, true);
236- try {
237- Set res = pn.getExpectedPolicies();
238- assertEquals(res.size(), hs.size());
239- assertEquals(res, hs);
240- } catch (Exception e) {
241- fail("Unexpected exception: " + e);
242- }
243- }
244-
245- /**
246- * @tests java.security.cert.PolicyNode#getPolicyQualifiers()
247- */
248- @TestTargetNew(
249- level = TestLevel.COMPLETE,
250- notes = "",
251- method = "getPolicyQualifiers",
252- args = {}
253- )
254- public final void test_getPolicyQualifiers() {
255- setUp1();
256- MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, hs, criticalityIndicator, null, true);
257- try {
258- Set res = pn.getPolicyQualifiers();
259- assertEquals(res.size(), hs.size());
260- assertEquals(res, hs);
261- } catch (Exception e) {
262- fail("Unexpected exception: " + e);
263- }
264- }
265-
266- /**
267- * @tests java.security.cert.PolicyNode#getChildren()
268- */
269- @TestTargetNew(
270- level = TestLevel.COMPLETE,
271- notes = "",
272- method = "getChildren",
273- args = {}
274- )
275- public final void test_getChildren() {
276- MyPolicyNode pn = new MyPolicyNode(null, anyPolicy, null, criticalityIndicator, null, true);
277- Iterator it = pn.getChildren();
278- try {
279- it.remove();
280- fail("UnsupportedOperationException was not thrown");
281- } catch (UnsupportedOperationException uoe) {
282- //expected
283- }
284- MyPolicyNode pn1 = new MyPolicyNode(pn, anyPolicy, null, criticalityIndicator, null, true);
285- try {
286- it = pn1.getChildren();
287- assertFalse(it.hasNext());
288- } catch (Exception e) {
289- fail("Unexpected exception: " + e);
290- }
291- }
292-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEntryImpl.java
+++ /dev/null
@@ -1,118 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.Principal;
21-import java.security.acl.*;
22-import java.util.Enumeration;
23-import java.util.Vector;
24-
25-/**
26- * Additional class for verification AclEntry interface
27- */
28-public class AclEntryImpl implements AclEntry {
29-
30- private Principal user;
31- private Vector permissionSet;
32- private boolean negative;
33-
34- public AclEntryImpl(Principal principal) {
35- user = null;
36- permissionSet = new Vector(10, 10);
37- negative = false;
38- user = principal;
39- }
40-
41- public AclEntryImpl() {
42- user = null;
43- permissionSet = new Vector(10, 10);
44- negative = false;
45- }
46-
47- public boolean setPrincipal(Principal principal) {
48- if(user != null) {
49- return false;
50- } else {
51- user = principal;
52- return true;
53- }
54- }
55-
56- public void setNegativePermissions() {
57- negative = true;
58- }
59-
60- public boolean isNegative() {
61- return negative;
62- }
63-
64- public boolean addPermission(Permission permission) {
65- if(permissionSet.contains(permission)) {
66- return false;
67- } else {
68- permissionSet.addElement(permission);
69- return true;
70- }
71- }
72-
73- public boolean removePermission(Permission permission) {
74- return permissionSet.removeElement(permission);
75- }
76-
77- public boolean checkPermission(Permission permission) {
78- return permissionSet.contains(permission);
79- }
80-
81- public Enumeration permissions() {
82- return permissionSet.elements();
83- }
84-
85- public String toString() {
86- StringBuffer stringbuffer = new StringBuffer();
87- if(negative)
88- stringbuffer.append("-");
89- else
90- stringbuffer.append("+");
91- if(user instanceof Group)
92- stringbuffer.append("Group.");
93- else
94- stringbuffer.append("User.");
95- stringbuffer.append((new StringBuilder()).append(user).append("=").toString());
96- Enumeration enumeration = permissions();
97- do {
98- if(!enumeration.hasMoreElements())
99- break;
100- Permission permission = (Permission)enumeration.nextElement();
101- stringbuffer.append(permission);
102- if(enumeration.hasMoreElements())
103- stringbuffer.append(",");
104- } while(true);
105- return new String(stringbuffer);
106- }
107-
108- public synchronized Object clone() {
109- AclEntryImpl aclentryimpl = new AclEntryImpl(user);
110- aclentryimpl.permissionSet = (Vector)permissionSet.clone();
111- aclentryimpl.negative = negative;
112- return aclentryimpl;
113- }
114-
115- public Principal getPrincipal() {
116- return user;
117- }
118-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclEnumerator.java
+++ /dev/null
@@ -1,51 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.acl.Acl;
21-import java.util.*;
22-
23-final class AclEnumerator implements Enumeration {
24-
25- Acl acl;
26- Enumeration u1;
27- Enumeration u2;
28- Enumeration g1;
29- Enumeration g2;
30-
31- AclEnumerator(Acl acl1, Hashtable hashtable, Hashtable hashtable1, Hashtable hashtable2, Hashtable hashtable3) {
32- acl = acl1;
33- u1 = hashtable.elements();
34- u2 = hashtable2.elements();
35- g1 = hashtable1.elements();
36- g2 = hashtable3.elements();
37- }
38-
39- public boolean hasMoreElements() {
40- return u1.hasMoreElements() || u2.hasMoreElements() || g1.hasMoreElements() || g2.hasMoreElements();
41- }
42-
43- public Object nextElement() {
44- Acl acl1 = acl;
45- if(u2.hasMoreElements()) return u2.nextElement();
46- if(g1.hasMoreElements()) return g1.nextElement();
47- if(u1.hasMoreElements()) return u1.nextElement();
48- if(g2.hasMoreElements()) return g2.nextElement();
49- return acl1;
50- }
51-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/AclImpl.java
+++ /dev/null
@@ -1,211 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.Principal;
21-import java.security.acl.*;
22-import java.util.*;
23-
24-/**
25- * Additional class for verification Acl interface
26- */
27-public class AclImpl extends OwnerImpl implements Acl {
28-
29- private Hashtable allowedUsersTable;
30- private Hashtable allowedGroupsTable;
31- private Hashtable deniedUsersTable;
32- private Hashtable deniedGroupsTable;
33- private String aclName;
34- private Vector zeroSet;
35-
36- public AclImpl(Principal principal, String s) {
37- super(principal);
38- allowedUsersTable = new Hashtable(23);
39- allowedGroupsTable = new Hashtable(23);
40- deniedUsersTable = new Hashtable(23);
41- deniedGroupsTable = new Hashtable(23);
42- aclName = null;
43- zeroSet = new Vector(1, 1);
44- try {
45- setName(principal, s);
46- } catch(Exception exception) { }
47- }
48-
49- public void setName(Principal principal, String s)
50- throws NotOwnerException {
51- if(!isOwner(principal)) {
52- throw new NotOwnerException();
53- } else {
54- aclName = s;
55- return;
56- }
57- }
58-
59- public String getName() {
60- return aclName;
61- }
62-
63- public synchronized boolean addEntry(Principal principal, AclEntry aclentry)
64- throws NotOwnerException {
65- if(!isOwner(principal)) throw new NotOwnerException();
66- Hashtable hashtable = findTable(aclentry);
67- Principal principal1 = aclentry.getPrincipal();
68- if(hashtable.get(principal1) != null) {
69- return false;
70- } else {
71- hashtable.put(principal1, aclentry);
72- return true;
73- }
74- }
75-
76- public synchronized boolean removeEntry(Principal principal, AclEntry aclentry)
77- throws NotOwnerException {
78- if(!isOwner(principal)) {
79- throw new NotOwnerException();
80- } else {
81- Hashtable hashtable = findTable(aclentry);
82- Principal principal1 = aclentry.getPrincipal();
83- Object obj = hashtable.remove(principal1);
84- return obj != null;
85- }
86- }
87-
88- public synchronized Enumeration getPermissions(Principal principal) {
89- Enumeration enumeration2 = subtract(getGroupPositive(principal), getGroupNegative(principal));
90- Enumeration enumeration3 = subtract(getGroupNegative(principal), getGroupPositive(principal));
91- Enumeration enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));
92- Enumeration enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));
93- Enumeration enumeration4 = subtract(enumeration2, enumeration1);
94- Enumeration enumeration5 = union(enumeration, enumeration4);
95- enumeration = subtract(getIndividualPositive(principal), getIndividualNegative(principal));
96- enumeration1 = subtract(getIndividualNegative(principal), getIndividualPositive(principal));
97- enumeration4 = subtract(enumeration3, enumeration);
98- Enumeration enumeration6 = union(enumeration1, enumeration4);
99- return subtract(enumeration5, enumeration6);
100- }
101-
102- public boolean checkPermission(Principal principal, Permission permission) {
103- for(Enumeration enumeration = getPermissions(principal); enumeration.hasMoreElements();) {
104- Permission permission1 = (Permission)enumeration.nextElement();
105- if(permission1.equals(permission))
106- return true;
107- }
108- return false;
109- }
110-
111- public synchronized Enumeration entries() {
112- return new AclEnumerator(this, allowedUsersTable, allowedGroupsTable, deniedUsersTable, deniedGroupsTable);
113- }
114-
115- public String toString() {
116- StringBuffer stringbuffer = new StringBuffer();
117- for(Enumeration enumeration = entries(); enumeration.hasMoreElements(); stringbuffer.append("\n")) {
118- AclEntry aclentry = (AclEntry)enumeration.nextElement();
119- stringbuffer.append(aclentry.toString().trim());
120- }
121- return stringbuffer.toString();
122- }
123-
124- private Hashtable findTable(AclEntry aclentry) {
125- Hashtable hashtable = null;
126- Principal principal = aclentry.getPrincipal();
127- if(principal instanceof Group) {
128- if(aclentry.isNegative())
129- hashtable = deniedGroupsTable;
130- else
131- hashtable = allowedGroupsTable;
132- } else
133- if(aclentry.isNegative())
134- hashtable = deniedUsersTable;
135- else
136- hashtable = allowedUsersTable;
137- return hashtable;
138- }
139-
140- private static Enumeration union(Enumeration enumeration, Enumeration enumeration1) {
141- Vector vector = new Vector(20, 20);
142- for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));
143- do {
144- if(!enumeration1.hasMoreElements())
145- break;
146- Object obj = enumeration1.nextElement();
147- if(!vector.contains(obj))
148- vector.addElement(obj);
149- } while(true);
150- return vector.elements();
151- }
152-
153- private Enumeration subtract(Enumeration enumeration, Enumeration enumeration1) {
154- Vector vector = new Vector(20, 20);
155- for(; enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));
156- do {
157- if(!enumeration1.hasMoreElements())
158- break;
159- Object obj = enumeration1.nextElement();
160- if(vector.contains(obj))
161- vector.removeElement(obj);
162- } while(true);
163- return vector.elements();
164- }
165-
166- private Enumeration getGroupPositive(Principal principal) {
167- Enumeration enumeration = zeroSet.elements();
168- Enumeration enumeration1 = allowedGroupsTable.keys();
169- do {
170- if(!enumeration1.hasMoreElements())
171- break;
172- Group group = (Group)enumeration1.nextElement();
173- if(group.isMember(principal)) {
174- AclEntry aclentry = (AclEntry)allowedGroupsTable.get(group);
175- enumeration = union(aclentry.permissions(), enumeration);
176- }
177- } while(true);
178- return enumeration;
179- }
180-
181- private Enumeration getGroupNegative(Principal principal) {
182- Enumeration enumeration = zeroSet.elements();
183- Enumeration enumeration1 = deniedGroupsTable.keys();
184- do {
185- if(!enumeration1.hasMoreElements())
186- break;
187- Group group = (Group)enumeration1.nextElement();
188- if(group.isMember(principal)) {
189- AclEntry aclentry = (AclEntry)deniedGroupsTable.get(group);
190- enumeration = union(aclentry.permissions(), enumeration);
191- }
192- } while(true);
193- return enumeration;
194- }
195-
196- private Enumeration getIndividualPositive(Principal principal) {
197- Enumeration enumeration = zeroSet.elements();
198- AclEntry aclentry = (AclEntry)allowedUsersTable.get(principal);
199- if(aclentry != null)
200- enumeration = aclentry.permissions();
201- return enumeration;
202- }
203-
204- private Enumeration getIndividualNegative(Principal principal) {
205- Enumeration enumeration = zeroSet.elements();
206- AclEntry aclentry = (AclEntry)deniedUsersTable.get(principal);
207- if(aclentry != null)
208- enumeration = aclentry.permissions();
209- return enumeration;
210- }
211-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/GroupImpl.java
+++ /dev/null
@@ -1,112 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.Principal;
21-import java.security.acl.Group;
22-import java.util.Enumeration;
23-import java.util.Vector;
24-
25-/**
26- * Additional class for verification Group interface
27- */
28-public class GroupImpl implements Group {
29-
30- private Vector groupMembers;
31- private String group;
32-
33- public GroupImpl(String s) {
34- groupMembers = new Vector(50, 100);
35- group = s;
36- }
37-
38- public boolean addMember(Principal principal) {
39- if(groupMembers.contains(principal))
40- return false;
41- if(group.equals(principal.toString())) {
42- throw new IllegalArgumentException();
43- } else {
44- groupMembers.addElement(principal);
45- return true;
46- }
47- }
48-
49- public boolean removeMember(Principal principal) {
50- return groupMembers.removeElement(principal);
51- }
52-
53- public Enumeration members() {
54- return groupMembers.elements();
55- }
56-
57- public boolean equals(Object obj) {
58- if(this == obj)
59- return true;
60- if(!(obj instanceof Group)) {
61- return false;
62- } else {
63- Group group1 = (Group)obj;
64- return group.equals(group1.toString());
65- }
66- }
67-
68- public boolean equals(Group group1) {
69- return equals(group1);
70- }
71-
72- public String toString() {
73- return group;
74- }
75-
76- public int hashCode() {
77- return group.hashCode();
78- }
79-
80- public boolean isMember(Principal principal) {
81- if(groupMembers.contains(principal)) {
82- return true;
83- } else {
84- Vector vector = new Vector(10);
85- return isMemberRecurse(principal, vector);
86- }
87- }
88-
89- public String getName() {
90- return group;
91- }
92-
93- boolean isMemberRecurse(Principal principal, Vector vector) {
94- for(Enumeration enumeration = members(); enumeration.hasMoreElements();) {
95- boolean flag = false;
96- Principal principal1 = (Principal)enumeration.nextElement();
97- if(principal1.equals(principal))
98- return true;
99- if(principal1 instanceof GroupImpl) {
100- GroupImpl groupimpl = (GroupImpl)principal1;
101- vector.addElement(this);
102- if(!vector.contains(groupimpl))
103- flag = groupimpl.isMemberRecurse(principal, vector);
104- } else if(principal1 instanceof Group) {
105- Group group1 = (Group)principal1;
106- if(!vector.contains(group1)) flag = group1.isMember(principal);
107- }
108- if(flag) return flag;
109- }
110- return false;
111- }
112-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/OwnerImpl.java
+++ /dev/null
@@ -1,69 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.Principal;
21-import java.security.acl.*;
22-import java.util.Enumeration;
23-
24-/**
25- * Additional class for verification Owner interface
26- */
27-public class OwnerImpl implements Owner {
28-
29- private Group ownerGroup;
30-
31- public OwnerImpl(Principal principal) {
32- ownerGroup = new GroupImpl("AclOwners");
33- ownerGroup.addMember(principal);
34- }
35-
36- public synchronized boolean addOwner(Principal principal, Principal principal1)
37- throws NotOwnerException {
38-
39- if(!isOwner(principal))
40- {
41- throw new NotOwnerException();
42- } else {
43- if (ownerGroup.isMember(principal1)) return false;
44- if (!ownerGroup.isMember(principal1)) {
45- ownerGroup.addMember(principal1);
46- return true;
47- }
48- }
49- return false;
50- }
51-
52- public synchronized boolean deleteOwner(Principal principal, Principal principal1)
53- throws NotOwnerException, LastOwnerException {
54-
55- if(!isOwner(principal)) throw new NotOwnerException();
56- Enumeration enumeration = ownerGroup.members();
57- Object obj = enumeration.nextElement();
58- if(enumeration.hasMoreElements()) {
59- return ownerGroup.removeMember(principal1);
60- } else {
61- throw new LastOwnerException();
62- }
63- }
64-
65- public synchronized boolean isOwner(Principal principal)
66- {
67- return ownerGroup.isMember(principal);
68- }
69-}
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PermissionImpl.java
+++ /dev/null
@@ -1,49 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.acl.Permission;
21-
22-/**
23- * Additional class for verification Permission interface
24- */
25-public class PermissionImpl implements Permission {
26-
27- private String permission;
28-
29- public PermissionImpl(String s) {
30- permission = s;
31- }
32-
33- public boolean equals(Object obj) {
34- if(obj instanceof Permission) {
35- Permission permission1 = (Permission)obj;
36- return permission.equals(permission1.toString());
37- } else {
38- return false;
39- }
40- }
41-
42- public String toString() {
43- return permission;
44- }
45-
46-/* public int hashCode() {
47- return toString().hashCode();
48- }*/
49-}
\ No newline at end of file
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/acl/PrincipalImpl.java
+++ /dev/null
@@ -1,53 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.acl;
19-
20-import java.security.Principal;
21-
22-/**
23- * Additional class for verification Principal interface
24- */
25-public class PrincipalImpl implements Principal {
26-
27- private String user;
28-
29- public PrincipalImpl(String s) {
30- user = s;
31- }
32-
33- public boolean equals(Object obj) {
34- if(obj instanceof PrincipalImpl) {
35- PrincipalImpl principalimpl = (PrincipalImpl)obj;
36- return user.equals(principalimpl.toString());
37- } else {
38- return false;
39- }
40- }
41-
42- public String toString() {
43- return user;
44- }
45-
46- public int hashCode() {
47- return user.hashCode();
48- }
49-
50- public String getName() {
51- return user;
52- }
53-}
--- a/libcore/support/src/test/java/org/apache/harmony/security/tests/support/cert/PolicyNodeImpl.java
+++ /dev/null
@@ -1,256 +0,0 @@
1-/*
2- * Licensed to the Apache Software Foundation (ASF) under one or more
3- * contributor license agreements. See the NOTICE file distributed with
4- * this work for additional information regarding copyright ownership.
5- * The ASF licenses this file to You under the Apache License, Version 2.0
6- * (the "License"); you may not use this file except in compliance with
7- * the License. You may obtain a copy of the License at
8- *
9- * http://www.apache.org/licenses/LICENSE-2.0
10- *
11- * Unless required by applicable law or agreed to in writing, software
12- * distributed under the License is distributed on an "AS IS" BASIS,
13- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14- * See the License for the specific language governing permissions and
15- * limitations under the License.
16- */
17-
18-package org.apache.harmony.security.tests.support.cert;
19-
20-import java.security.cert.PolicyNode;
21-import java.util.*;
22-
23-public class PolicyNodeImpl implements PolicyNode {
24-
25- private static final String ANY_POLICY = "2.5.29.32.0";
26- private PolicyNodeImpl mParent;
27- private HashSet mChildren;
28- private String mValidPolicy;
29- private HashSet mQualifierSet;
30- private boolean mCriticalityIndicator;
31- private HashSet mExpectedPolicySet;
32- private boolean mOriginalExpectedPolicySet;
33- private int mDepth;
34- private boolean isImmutable;
35-
36- public PolicyNodeImpl(PolicyNodeImpl policynodeimpl, String s, Set set,
37- boolean flag, Set set1, boolean flag1) {
38- isImmutable = false;
39- mParent = policynodeimpl;
40- mChildren = new HashSet();
41- if(s != null) {
42- mValidPolicy = s;
43- } else {
44- mValidPolicy = "";
45- }
46- if(set != null) {
47- mQualifierSet = new HashSet(set);
48- } else {
49- mQualifierSet = new HashSet();
50- }
51- mCriticalityIndicator = flag;
52- if(set1 != null) {
53- mExpectedPolicySet = new HashSet(set1);
54- } else {
55- mExpectedPolicySet = new HashSet();
56- }
57- mOriginalExpectedPolicySet = !flag1;
58- if(mParent != null) {
59- mDepth = mParent.getDepth() + 1;
60- mParent.addChild(this);
61- } else {
62- mDepth = 0;
63- }
64- }
65-
66- PolicyNodeImpl(PolicyNodeImpl policynodeimpl,
67- PolicyNodeImpl policynodeimpl1) {
68- this(policynodeimpl, policynodeimpl1.mValidPolicy, ((Set) (policynodeimpl1.mQualifierSet)), policynodeimpl1.mCriticalityIndicator, ((Set) (policynodeimpl1.mExpectedPolicySet)), false);
69- }
70-
71- public PolicyNode getParent() {
72- return mParent;
73- }
74-
75- public Iterator getChildren() {
76- return Collections.unmodifiableSet(mChildren).iterator();
77- }
78-
79- public int getDepth() {
80- return mDepth;
81- }
82-
83- public String getValidPolicy() {
84- return mValidPolicy;
85- }
86-
87- public Set getPolicyQualifiers() {
88- return Collections.unmodifiableSet(mQualifierSet);
89- }
90-
91- public Set getExpectedPolicies() {
92- return Collections.unmodifiableSet(mExpectedPolicySet);
93- }
94-
95- public boolean isCritical() {
96- return mCriticalityIndicator;
97- }
98-
99- public String toString() {
100- StringBuffer stringbuffer = new StringBuffer(asString());
101- for(Iterator iterator = getChildren(); iterator.hasNext(); stringbuffer.append((PolicyNodeImpl)iterator.next()));
102- return stringbuffer.toString();
103- }
104-
105- boolean isImmutable() {
106- return isImmutable;
107- }
108-
109- void setImmutable() {
110- if(isImmutable) return;
111- PolicyNodeImpl policynodeimpl;
112- for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl.setImmutable())
113- policynodeimpl = (PolicyNodeImpl)iterator.next();
114-
115- isImmutable = true;
116- }
117-
118- private void addChild(PolicyNodeImpl policynodeimpl) {
119- if(isImmutable) {
120- throw new IllegalStateException("PolicyNode is immutable");
121- } else {
122- mChildren.add(policynodeimpl);
123- return;
124- }
125- }
126-
127- void addExpectedPolicy(String s) {
128- if(isImmutable)
129- throw new IllegalStateException("PolicyNode is immutable");
130- if(mOriginalExpectedPolicySet) {
131- mExpectedPolicySet.clear();
132- mOriginalExpectedPolicySet = false;
133- }
134- mExpectedPolicySet.add(s);
135- }
136-
137- void prune(int i) {
138- if(isImmutable)
139- throw new IllegalStateException("PolicyNode is immutable");
140- if(mChildren.size() == 0)
141- return;
142- Iterator iterator = mChildren.iterator();
143- do {
144- if(!iterator.hasNext()) break;
145- PolicyNodeImpl policynodeimpl = (PolicyNodeImpl)iterator.next();
146- policynodeimpl.prune(i);
147- if(policynodeimpl.mChildren.size() == 0 && i > mDepth + 1)
148- iterator.remove();
149- } while(true);
150- }
151-
152- void deleteChild(PolicyNode policynode) {
153- if(isImmutable) {
154- throw new IllegalStateException("PolicyNode is immutable");
155- } else {
156- mChildren.remove(policynode);
157- return;
158- }
159- }
160-
161- PolicyNodeImpl copyTree() {
162- return copyTree(null);
163- }
164-
165- private PolicyNodeImpl copyTree(PolicyNodeImpl policynodeimpl) {
166- PolicyNodeImpl policynodeimpl1 = new PolicyNodeImpl(policynodeimpl, this);
167- PolicyNodeImpl policynodeimpl2;
168- for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl2.copyTree(policynodeimpl1))
169- policynodeimpl2 = (PolicyNodeImpl)iterator.next();
170-
171- return policynodeimpl1;
172- }
173-
174- Set getPolicyNodes(int i) {
175- HashSet hashset = new HashSet();
176- getPolicyNodes(i, ((Set) (hashset)));
177- return hashset;
178- }
179-
180- private void getPolicyNodes(int i, Set set) {
181- if(mDepth == i) {
182- set.add(this);
183- } else {
184- PolicyNodeImpl policynodeimpl;
185- for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); policynodeimpl.getPolicyNodes(i, set))
186- policynodeimpl = (PolicyNodeImpl)iterator.next();
187- }
188- }
189-
190- Set getPolicyNodesExpected(int i, String s, boolean flag) {
191- if(s.equals("2.5.29.32.0"))
192- return getPolicyNodes(i);
193- else
194- return getPolicyNodesExpectedHelper(i, s, flag);
195- }
196-
197- private Set getPolicyNodesExpectedHelper(int i, String s, boolean flag) {
198- HashSet hashset = new HashSet();
199- if(mDepth < i) {
200- PolicyNodeImpl policynodeimpl;
201- for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); hashset.addAll(policynodeimpl.getPolicyNodesExpectedHelper(i, s, flag)))
202- policynodeimpl = (PolicyNodeImpl)iterator.next();
203-
204- } else if(flag) {
205- if(mExpectedPolicySet.contains("2.5.29.32.0"))
206- hashset.add(this);
207- } else if(mExpectedPolicySet.contains(s)) {
208- hashset.add(this);
209- }
210- return hashset;
211- }
212-
213- Set getPolicyNodesValid(int i, String s) {
214- HashSet hashset = new HashSet();
215- if(mDepth < i) {
216- PolicyNodeImpl policynodeimpl;
217- for(Iterator iterator = mChildren.iterator(); iterator.hasNext(); hashset.addAll(policynodeimpl.getPolicyNodesValid(i, s)))
218- policynodeimpl = (PolicyNodeImpl)iterator.next();
219-
220- } else if(mValidPolicy.equals(s)) {
221- hashset.add(this);
222- }
223- return hashset;
224- }
225-
226- private static String policyToString(String s) {
227- if(s.equals("2.5.29.32.0")) {
228- return "anyPolicy";
229- } else {
230- return s;
231- }
232- }
233-
234- String asString() {
235- if(mParent == null)
236- return "anyPolicy ROOT\n";
237- StringBuffer stringbuffer = new StringBuffer();
238- int i = 0;
239- for(int j = getDepth(); i < j; i++)
240- stringbuffer.append(" ");
241-
242- stringbuffer.append(policyToString(getValidPolicy()));
243- stringbuffer.append(" CRIT: ");
244- stringbuffer.append(isCritical());
245- stringbuffer.append(" EP: ");
246- for(Iterator iterator = getExpectedPolicies().iterator(); iterator.hasNext(); stringbuffer.append(" ")) {
247- String s = (String)iterator.next();
248- stringbuffer.append(policyToString(s));
249- }
250-
251- stringbuffer.append(" (");
252- stringbuffer.append(getDepth());
253- stringbuffer.append(")\n");
254- return stringbuffer.toString();
255- }
256-}
--- a/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
+++ b/libcore/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
@@ -153,7 +153,7 @@ public class NumberFormatTest extends TestCase {
153153 Locale chLocale = new Locale("de", "CH");
154154 // END android-added
155155
156- Locale[] requiredLocales = {usLocale, chLocale};
156+ Locale[] requiredLocales = {usLocale, arLocale, chLocale};
157157 if (!Support_Locale.areLocalesAvailable(requiredLocales)) {
158158 // locale dependent test, bug 1943269
159159 return;
--- a/vm/native/dalvik_system_Zygote.c
+++ b/vm/native/dalvik_system_Zygote.c
@@ -324,10 +324,38 @@ static void enableDebugFeatures(u4 debugFlags)
324324 #endif
325325 }
326326
327-/*
327+/*
328+ * Set Linux capability flags.
329+ *
330+ * Returns 0 on success, errno on failure.
331+ */
332+static int setCapabilities(int64_t permitted, int64_t effective)
333+{
334+#ifdef HAVE_ANDROID_OS
335+ struct __user_cap_header_struct capheader;
336+ struct __user_cap_data_struct capdata;
337+
338+ memset(&capheader, 0, sizeof(capheader));
339+ memset(&capdata, 0, sizeof(capdata));
340+
341+ capheader.version = _LINUX_CAPABILITY_VERSION;
342+ capheader.pid = 0;
343+
344+ capdata.effective = effective;
345+ capdata.permitted = permitted;
346+
347+ LOGV("CAPSET perm=%llx eff=%llx\n", permitted, effective);
348+ if (capset(&capheader, &capdata) != 0)
349+ return errno;
350+#endif /*HAVE_ANDROID_OS*/
351+
352+ return 0;
353+}
354+
355+/*
328356 * Utility routine to fork zygote and specialize the child process.
329357 */
330-static pid_t forkAndSpecializeCommon(const u4* args)
358+static pid_t forkAndSpecializeCommon(const u4* args, bool isSystemServer)
331359 {
332360 pid_t pid;
333361
@@ -336,6 +364,21 @@ static pid_t forkAndSpecializeCommon(const u4* args)
336364 ArrayObject* gids = (ArrayObject *)args[2];
337365 u4 debugFlags = args[3];
338366 ArrayObject *rlimits = (ArrayObject *)args[4];
367+ int64_t permittedCapabilities, effectiveCapabilities;
368+
369+ if (isSystemServer) {
370+ /*
371+ * Don't use GET_ARG_LONG here for now. gcc is generating code
372+ * that uses register d8 as a temporary, and that's coming out
373+ * scrambled in the child process. b/3138621
374+ */
375+ //permittedCapabilities = GET_ARG_LONG(args, 5);
376+ //effectiveCapabilities = GET_ARG_LONG(args, 7);
377+ permittedCapabilities = args[5] | (int64_t) args[6] << 32;
378+ effectiveCapabilities = args[7] | (int64_t) args[8] << 32;
379+ } else {
380+ permittedCapabilities = effectiveCapabilities = 0;
381+ }
339382
340383 if (!gDvm.zygote) {
341384 dvmThrowException("Ljava/lang/IllegalStateException;",
@@ -367,7 +410,8 @@ static pid_t forkAndSpecializeCommon(const u4* args)
367410 err = prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
368411
369412 if (err < 0) {
370- LOGW("cannot PR_SET_KEEPCAPS errno: %d", errno);
413+ LOGE("cannot PR_SET_KEEPCAPS: %s", strerror(errno));
414+ dvmAbort();
371415 }
372416 }
373417
@@ -376,23 +420,34 @@ static pid_t forkAndSpecializeCommon(const u4* args)
376420 err = setgroupsIntarray(gids);
377421
378422 if (err < 0) {
379- LOGW("cannot setgroups() errno: %d", errno);
423+ LOGE("cannot setgroups(): %s", strerror(errno));
424+ dvmAbort();
380425 }
381426
382427 err = setrlimitsFromArray(rlimits);
383428
384429 if (err < 0) {
385- LOGW("cannot setrlimit() errno: %d", errno);
430+ LOGE("cannot setrlimit(): %s", strerror(errno));
431+ dvmAbort();
386432 }
387433
388434 err = setgid(gid);
389435 if (err < 0) {
390- LOGW("cannot setgid(%d) errno: %d", gid, errno);
436+ LOGE("cannot setgid(%d): %s", gid, strerror(errno));
437+ dvmAbort();
391438 }
392439
393440 err = setuid(uid);
394441 if (err < 0) {
395- LOGW("cannot setuid(%d) errno: %d", uid, errno);
442+ LOGE("cannot setuid(%d): %s", uid, strerror(errno));
443+ dvmAbort();
444+ }
445+
446+ err = setCapabilities(permittedCapabilities, effectiveCapabilities);
447+ if (err != 0) {
448+ LOGE("cannot set capabilities (%llx,%llx): %s\n",
449+ permittedCapabilities, effectiveCapabilities, strerror(err));
450+ dvmAbort();
396451 }
397452
398453 /*
@@ -425,19 +480,20 @@ static void Dalvik_dalvik_system_Zygote_forkAndSpecialize(const u4* args,
425480 {
426481 pid_t pid;
427482
428- pid = forkAndSpecializeCommon(args);
483+ pid = forkAndSpecializeCommon(args, false);
429484
430485 RETURN_INT(pid);
431486 }
432487
433-/* native public static int forkSystemServer(int uid, int gid,
434- * int[] gids, int debugFlags);
488+/* native public static int forkSystemServer(int uid, int gid,
489+ * int[] gids, int debugFlags, long permittedCapabilities,
490+ * long effectiveCapabilities);
435491 */
436492 static void Dalvik_dalvik_system_Zygote_forkSystemServer(
437493 const u4* args, JValue* pResult)
438494 {
439495 pid_t pid;
440- pid = forkAndSpecializeCommon(args);
496+ pid = forkAndSpecializeCommon(args, true);
441497
442498 /* The zygote process checks whether the child process has died or not. */
443499 if (pid > 0) {
@@ -462,7 +518,7 @@ const DalvikNativeMethod dvm_dalvik_system_Zygote[] = {
462518 Dalvik_dalvik_system_Zygote_fork },
463519 { "forkAndSpecialize", "(II[II[[I)I",
464520 Dalvik_dalvik_system_Zygote_forkAndSpecialize },
465- { "forkSystemServer", "(II[II[[I)I",
521+ { "forkSystemServer", "(II[II[[IJJ)I",
466522 Dalvik_dalvik_system_Zygote_forkSystemServer },
467523 { NULL, NULL, NULL },
468524 };
Show on old repository browser