diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0ae53de58..93e9749ac 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -22,6 +22,11 @@
+
+ Use correct type bounds in
+ "CollectionUtils#isEqualCollection(Collection, Collection, Equator)" to
+ prevent a "ClassCastException" at runtime for invalid inputs.
+
Removed unneeded private method in "PassiveExpiringMap".
diff --git a/src/main/java/org/apache/commons/collections4/CollectionUtils.java b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
index 777fb2e22..6f3937494 100644
--- a/src/main/java/org/apache/commons/collections4/CollectionUtils.java
+++ b/src/main/java/org/apache/commons/collections4/CollectionUtils.java
@@ -534,7 +534,13 @@ public class CollectionUtils {
* That is, iff the cardinality of e in a is
* equal to the cardinality of e in b,
* for each element e in a or b.
+ *
+ * Note: from version 4.1 onwards this method requires the input
+ * collections and equator to be of compatible type (using bounded wildcards).
+ * Providing incompatible arguments (e.g. by casting to their rawtypes)
+ * will result in a {@code ClassCastException} thrown at runtime.
*
+ * @param the element type
* @param a the first collection, must not be null
* @param b the second collection, must not be null
* @param equator the Equator used for testing equality
@@ -542,8 +548,9 @@ public class CollectionUtils {
* @throws IllegalArgumentException if the equator is null
* @since 4.0
*/
- @SuppressWarnings({ "unchecked", "rawtypes" }) // we don't know the types due to wildcards in the signature
- public static boolean isEqualCollection(final Collection> a, final Collection> b, final Equator> equator) {
+ public static boolean isEqualCollection(final Collection extends E> a,
+ final Collection extends E> b,
+ final Equator super E> equator) {
if (equator == null) {
throw new IllegalArgumentException("equator may not be null");
}
@@ -552,7 +559,8 @@ public class CollectionUtils {
return false;
}
- final Transformer transformer = new Transformer() {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ final Transformer transformer = new Transformer() {
public EquatorWrapper> transform(final Object input) {
return new EquatorWrapper(equator, input);
}