diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 5a646b75e..5b0070dd8 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -22,6 +22,10 @@ + + Deprecated methods "synchronizedCollection(Collection)" and "unmodifiableCollection(Collection)" + in class "CollectionUtils", the corresponding methods in "java.util.Collections" should be used instead. + "IteratorUtils#collate(...)" methods did not use natural ordering when a null comparator was provided. diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java index 7011755f9..32ca11b07 100644 --- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java +++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java @@ -1808,7 +1808,9 @@ public class CollectionUtils { * @param collection the collection to synchronize, must not be null * @return a synchronized collection backed by the given collection * @throws IllegalArgumentException if the collection is null + * @deprecated since 4.1, use {@link java.util.Collections#synchronizedCollection(Collection)} instead */ + @Deprecated public static Collection synchronizedCollection(final Collection collection) { return SynchronizedCollection.synchronizedCollection(collection); } @@ -1822,7 +1824,9 @@ public class CollectionUtils { * @param collection the collection to make unmodifiable, must not be null * @return an unmodifiable collection backed by the given collection * @throws IllegalArgumentException if the collection is null + * @deprecated since 4.1, use {@link java.util.Collections#unmodifiableCollection(Collection)} instead */ + @Deprecated public static Collection unmodifiableCollection(final Collection collection) { return UnmodifiableCollection.unmodifiableCollection(collection); } diff --git a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java index 851b0dd19..63fd19bde 100644 --- a/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java +++ b/src/test/java/org/apache/commons/collections4/CollectionUtilsTest.java @@ -1524,18 +1524,20 @@ public class CollectionUtilsTest extends MockTestCase { } @Test + @Deprecated public void testSynchronizedCollection() { Collection col = CollectionUtils.synchronizedCollection(new ArrayList()); assertTrue("Returned object should be a SynchronizedCollection.", col instanceof SynchronizedCollection); try { CollectionUtils.synchronizedCollection(null); - fail("Expecting IllegalArgumentException for null collection."); - } catch (final IllegalArgumentException ex) { + fail("Expecting NullPointerException for null collection."); + } catch (final NullPointerException ex) { // expected } } @Test + @Deprecated public void testUnmodifiableCollection() { Collection col = CollectionUtils.unmodifiableCollection(new ArrayList()); assertTrue("Returned object should be a UnmodifiableCollection.", col instanceof UnmodifiableCollection);