harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r379447 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Collections.java test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
Date Tue, 21 Feb 2006 13:21:33 GMT
Author: tellison
Date: Tue Feb 21 05:21:31 2006
New Revision: 379447

URL: http://svn.apache.org/viewcvs?rev=379447&view=rev
Log:
- Fix for HARMONY-93 (some methods in java.util.Collections don't throw NPE when the parameter
is null)
- marked a number of invariant fields final
- implemented synchronized versions of toString

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java?rev=379447&r1=379446&r2=379447&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Collections.java
Tue Feb 21 05:21:31 2006
@@ -30,9 +30,9 @@
 			Serializable {
 		private static final long serialVersionUID = 2739099268398711800L;
 
-		private int n;
+		private final int n;
 
-		private Object element;
+		private final Object element;
 
 		CopiesList(int length, Object object) {
 			if (length < 0) {
@@ -150,7 +150,7 @@
 			Serializable {
 		private static final long serialVersionUID = 3193687207550431679L;
 
-		Object element;
+		final Object element;
 
 		SingletonSet(Object object) {
 			element = object;
@@ -191,7 +191,7 @@
 			Serializable {
 		private static final long serialVersionUID = 3093736618740652951L;
 
-		Object element;
+		final Object element;
 
 		SingletonList(Object object) {
 			element = object;
@@ -216,7 +216,7 @@
 			Serializable {
 		private static final long serialVersionUID = -6979724477215052911L;
 
-		Object k, v;
+		final Object k, v;
 
 		SingletonMap(Object key, Object value) {
 			k = key;
@@ -305,9 +305,8 @@
 	static class SynchronizedCollection implements Collection, Serializable {
 		private static final long serialVersionUID = 3053995032091335093L;
 
-		Collection c;
-
-		Object mutex;
+		final Collection c;
+		final Object mutex;
 
 		SynchronizedCollection(Collection collection) {
 			c = collection;
@@ -391,6 +390,12 @@
 			}
 		}
 
+		public String toString() {
+			synchronized (mutex) {
+				return c.toString();
+			}
+		}
+
 		public Object[] toArray(Object[] array) {
 			synchronized (mutex) {
 				return c.toArray(array);
@@ -414,7 +419,6 @@
 
 		SynchronizedRandomAccessList(List l, Object mutex) {
 			super(l, mutex);
-			list = l;
 		}
 
 		public List subList(int start, int end) {
@@ -443,7 +447,7 @@
 			List {
 		private static final long serialVersionUID = -7754090372962971524L;
 
-		List list;
+		final List list;
 
 		SynchronizedList(List l) {
 			super(l);
@@ -558,9 +562,8 @@
 	static class SynchronizedMap implements Map, Serializable {
 		private static final long serialVersionUID = 1978198479659022715L;
 
-		private Map m;
-
-		Object mutex;
+		private final Map m;
+		final Object mutex;
 
 		SynchronizedMap(Map map) {
 			m = map;
@@ -656,6 +659,12 @@
 			}
 		}
 
+		public String toString() {
+			synchronized (mutex) {
+				return m.toString();
+			}
+		}
+
 		private void writeObject(ObjectOutputStream stream) throws IOException {
 			synchronized (mutex) {
 				stream.defaultWriteObject();
@@ -697,7 +706,7 @@
 			SortedMap {
 		private static final long serialVersionUID = -8798146769416483793L;
 
-		private SortedMap sm;
+		private final SortedMap sm;
 
 		SynchronizedSortedMap(SortedMap map) {
 			super(map);
@@ -757,7 +766,7 @@
 			SortedSet {
 		private static final long serialVersionUID = 8695801310862127406L;
 
-		private SortedSet ss;
+		private final SortedSet ss;
 
 		SynchronizedSortedSet(SortedSet set) {
 			super(set);
@@ -816,7 +825,7 @@
 			Serializable {
 		private static final long serialVersionUID = 1820017752578914078L;
 
-		Collection c;
+		final Collection c;
 
 		UnmodifiableCollection(Collection collection) {
 			c = collection;
@@ -920,7 +929,7 @@
 			implements List {
 		private static final long serialVersionUID = -283967356065247728L;
 
-		List list;
+		final List list;
 
 		UnmodifiableList(List l) {
 			super(l);
@@ -1039,7 +1048,7 @@
 	private static class UnmodifiableMap implements Map, Serializable {
 		private static final long serialVersionUID = -1034234728574286014L;
 
-		private Map m;
+		private final Map m;
 
 		private static class UnmodifiableEntrySet extends UnmodifiableSet {
 			private static final long serialVersionUID = 7854390611657943733L;
@@ -1204,7 +1213,7 @@
 			implements SortedMap {
 		private static final long serialVersionUID = -8806743815996713206L;
 
-		private SortedMap sm;
+		private final SortedMap sm;
 
 		UnmodifiableSortedMap(SortedMap map) {
 			super(map);
@@ -1240,7 +1249,7 @@
 			implements SortedSet {
 		private static final long serialVersionUID = -4929149591599911165L;
 
-		private SortedSet ss;
+		private final SortedSet ss;
 
 		UnmodifiableSortedSet(SortedSet set) {
 			super(set);
@@ -1968,6 +1977,8 @@
 	 * @return a synchronized Collection
 	 */
 	public static Collection synchronizedCollection(Collection collection) {
+		if (collection == null)
+			throw new NullPointerException();
 		return new SynchronizedCollection(collection);
 	}
 
@@ -1997,6 +2008,8 @@
 	 * @return a synchronized Map
 	 */
 	public static Map synchronizedMap(Map map) {
+		if (map == null)
+			throw new NullPointerException();
 		return new SynchronizedMap(map);
 	}
 
@@ -2009,6 +2022,8 @@
 	 * @return a synchronized Set
 	 */
 	public static Set synchronizedSet(Set set) {
+		if (set == null)
+			throw new NullPointerException();
 		return new SynchronizedSet(set);
 	}
 
@@ -2021,6 +2036,8 @@
 	 * @return a synchronized SortedMap
 	 */
 	public static SortedMap synchronizedSortedMap(SortedMap map) {
+		if (map == null)
+			throw new NullPointerException();
 		return new SynchronizedSortedMap(map);
 	}
 
@@ -2033,6 +2050,8 @@
 	 * @return a synchronized SortedSet
 	 */
 	public static SortedSet synchronizedSortedSet(SortedSet set) {
+		if (set == null)
+			throw new NullPointerException();
 		return new SynchronizedSortedSet(set);
 	}
 
@@ -2046,6 +2065,8 @@
 	 * @return an unmodifiable Collection
 	 */
 	public static Collection unmodifiableCollection(Collection collection) {
+		if (collection == null)
+			throw new NullPointerException();
 		return new UnmodifiableCollection(collection);
 	}
 
@@ -2077,6 +2098,8 @@
 	 * @return a unmodifiable Map
 	 */
 	public static Map unmodifiableMap(Map map) {
+		if (map == null)
+			throw new NullPointerException();
 		return new UnmodifiableMap(map);
 	}
 
@@ -2090,6 +2113,8 @@
 	 * @return a unmodifiable Set
 	 */
 	public static Set unmodifiableSet(Set set) {
+		if (set == null)
+			throw new NullPointerException();
 		return new UnmodifiableSet(set);
 	}
 
@@ -2103,6 +2128,8 @@
 	 * @return a unmodifiable SortedMap
 	 */
 	public static SortedMap unmodifiableSortedMap(SortedMap map) {
+		if (map == null)
+			throw new NullPointerException();
 		return new UnmodifiableSortedMap(map);
 	}
 
@@ -2116,6 +2143,8 @@
 	 * @return a unmodifiable SortedSet
 	 */
 	public static SortedSet unmodifiableSortedSet(SortedSet set) {
+		if (set == null)
+			throw new NullPointerException();
 		return new UnmodifiableSortedSet(set);
 	}
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java?rev=379447&r1=379446&r2=379447&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/util/CollectionsTest.java
Tue Feb 21 05:21:31 2006
@@ -30,7 +30,7 @@
 	public void test_rotateLjava_util_ListI() {
 		// Regression for HARMONY-19 Rotate an *empty* list
 		Collections.rotate(new ArrayList(), 25);
-		
+
 		// Regression for HARMONY-20
 		List list = new ArrayList();
 		list.add(0, "zero");
@@ -50,5 +50,135 @@
 				(String) list.get(3));
 		assertEquals("Rotated incorrectly at position 4, ", "two",
 				(String) list.get(4));
+	}
+
+	/**
+	 * @tests java.util.Collections#synchronizedCollection(java.util.Collection)
+	 */
+	public void test_synchronizedCollectionLjava_util_Collection() {
+		try {
+			// Regression for HARMONY-93
+			Collections.synchronizedCollection(null);
+			fail("Assert 0: synchronizedCollection(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#synchronizedSortedMap(java.util.SortedMap)
+	 */
+	public void test_synchronizedSortedMapLjava_util_SortedMap() {
+		try {
+			// Regression for HARMONY-93
+			Collections.synchronizedSortedMap(null);
+			fail("Assert 0: synchronizedSortedMap(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#synchronizedMap(java.util.Map)
+	 */
+	public void test_synchronizedMapLjava_util_Map() {
+		try {
+			// Regression for HARMONY-93
+			Collections.synchronizedMap(null);
+			fail("Assert 0: synchronizedMap(map) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#synchronizedSet(java.util.Set)
+	 */
+	public void test_synchronizedSetLjava_util_Set() {
+		try {
+			// Regression for HARMONY-93
+			Collections.synchronizedSet(null);
+			fail("Assert 0: synchronizedSet(set) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#synchronizedSortedSet(java.util.SortedSet)
+	 */
+	public void test_synchronizedSortedSetLjava_util_SortedSet() {
+		try {
+			// Regression for HARMONY-93
+			Collections.synchronizedSortedSet(null);
+			fail("Assert 0: synchronizedSortedSet(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#unmodifiableCollection(java.util.Collection)
+	 */
+	public void test_unmodifiableCollectionLjava_util_Collection() {
+		try {
+			// Regression for HARMONY-93
+			Collections.unmodifiableCollection(null);
+			fail("Assert 0: unmodifiableCollection(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#unmodifiableMap(java.util.Map)
+	 */
+	public void test_unmodifiableMapLjava_util_Map() {
+		try {
+			// Regression for HARMONY-93
+			Collections.unmodifiableMap(null);
+			fail("Assert 0: unmodifiableMap(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#unmodifiableSet(java.util.Set)
+	 */
+	public void test_unmodifiableSetLjava_util_Set() {
+		try {
+			// Regression for HARMONY-93
+			Collections.unmodifiableSet(null);
+			fail("Assert 0: unmodifiableSet(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#unmodifiableSortedMap(java.util.SortedMap)
+	 */
+	public void test_unmodifiableSortedMapLjava_util_SortedMap() {
+		try {
+			// Regression for HARMONY-93
+			Collections.unmodifiableSortedMap(null);
+			fail("Assert 0: unmodifiableSortedMap(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
+	}
+
+	/**
+	 * @tests java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
+	 */
+	public void test_unmodifiableSortedSetLjava_util_SortedSet() {
+		try {
+			// Regression for HARMONY-93
+			Collections.unmodifiableSortedSet(null);
+			fail("Assert 0: unmodifiableSortedSet(null) must throw NPE");
+		} catch (NullPointerException e) {
+			// expected
+		}
 	}
 }



Mime
View raw message