You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2014/05/29 20:31:56 UTC
svn commit: r1598357 - in /commons/proper/collections/trunk/src:
changes/changes.xml
main/java/org/apache/commons/collections4/CollectionUtils.java
Author: tn
Date: Thu May 29 18:31:56 2014
New Revision: 1598357
URL: http://svn.apache.org/r1598357
Log:
[COLLECTIONS-531] Use proper type bounds for CollectionUtils.isEqualCollection(C, C, Equator). Thanks to Dipanjan Laha.
Modified:
commons/proper/collections/trunk/src/changes/changes.xml
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
Modified: commons/proper/collections/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/changes/changes.xml?rev=1598357&r1=1598356&r2=1598357&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/changes/changes.xml (original)
+++ commons/proper/collections/trunk/src/changes/changes.xml Thu May 29 18:31:56 2014
@@ -22,6 +22,11 @@
<body>
<release version="4.1" date="TBD" description="">
+ <action issue="COLLECTIONS-531" dev="tn" type="fix" due-to="Dipanjan Laha">
+ Use correct type bounds in
+ "CollectionUtils#isEqualCollection(Collection, Collection, Equator)" to
+ prevent a "ClassCastException" at runtime for invalid inputs.
+ </action>
<action issue="COLLECTIONS-523" dev="tn" type="fix" due-to="Thiago Andrade">
Removed unneeded private method in "PassiveExpiringMap".
</action>
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java?rev=1598357&r1=1598356&r2=1598357&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/CollectionUtils.java Thu May 29 18:31:56 2014
@@ -534,7 +534,13 @@ public class CollectionUtils {
* That is, iff the cardinality of <i>e</i> in <i>a</i> is
* equal to the cardinality of <i>e</i> in <i>b</i>,
* for each element <i>e</i> in <i>a</i> or <i>b</i>.
+ * <p>
+ * <b>Note:</b> 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 <E> 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 <E> 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<E, ?> transformer = new Transformer() {
public EquatorWrapper<?> transform(final Object input) {
return new EquatorWrapper(equator, input);
}