From 0acb702f3e6a6a3900d75f2b1df2aca76e853f11 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 22 Jun 2015 10:17:20 +0000 Subject: [PATCH] [COLLECTIONS-571] Deprecate CollectionUtils.{synchronized,unmodifiable}Collection. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/collections/trunk@1686826 13f79535-47bb-0310-9956-ffa450edef68 --- src/changes/changes.xml | 4 ++++ .../org/apache/commons/collections4/CollectionUtils.java | 4 ++++ .../apache/commons/collections4/CollectionUtilsTest.java | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) 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);