diff --git a/classpath/java/security/AccessController.java b/classpath/java/security/AccessController.java index 680f0ec125..a9818d97ae 100644 --- a/classpath/java/security/AccessController.java +++ b/classpath/java/security/AccessController.java @@ -18,7 +18,7 @@ package java.security; */ public class AccessController { - public static Object doPrivileged (PrivilegedAction action) { + public static T doPrivileged (PrivilegedAction action) { return action.run(); } diff --git a/classpath/java/util/Collections.java b/classpath/java/util/Collections.java index a098ea8b2e..e674982e16 100644 --- a/classpath/java/util/Collections.java +++ b/classpath/java/util/Collections.java @@ -340,7 +340,101 @@ public class Collections { } public static Set synchronizedSet(Set set) { - return new SynchronizedSet (new Object(), set); + return new SynchronizedSet (set, set); + } + + static class SynchronizedList + extends SynchronizedCollection + implements List + { + private final List list; + + public SynchronizedList(List list) { + super(list, list); + + this.list = list; + } + + @Override + public T get(int index) { + synchronized (lock) { + return list.get(index); + } + } + + @Override + public T set(int index, T value) { + synchronized (lock) { + return list.set(index, value); + } + } + + @Override + public T remove(int index) { + synchronized (lock) { + return list.remove(index); + } + } + + @Override + public void add(int index, T element) { + synchronized (lock) { + list.add(index, element); + } + } + + @Override + public boolean addAll(int startIndex, Collection c) { + synchronized (lock) { + return list.addAll(startIndex, c); + } + } + + @Override + public int indexOf(Object value) { + synchronized (lock) { + return list.indexOf(value); + } + } + + @Override + public int lastIndexOf(Object value) { + synchronized (lock) { + return list.lastIndexOf(value); + } + } + + @Override + public ListIterator listIterator(int index) { + // as described in the javadocs, user should be synchronized on list before calling + return list.listIterator(index); + } + + @Override + public ListIterator listIterator() { + // as described in the javadocs, user should be synchronized on list before calling + return list.listIterator(); + } + } + + static class RandomAccessSynchronizedList + extends SynchronizedList + implements RandomAccess + { + public RandomAccessSynchronizedList(List list) { + super(list); + } + } + + public static List synchronizedList(List list) { + List result; + if (list instanceof RandomAccess) { + result = new RandomAccessSynchronizedList(list); + } else { + result = new SynchronizedList(list); + } + + return result; } static class SynchronizedIterator implements Iterator {