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 2013/02/26 22:04:38 UTC
svn commit: r1450421 -
/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java
Author: tn
Date: Tue Feb 26 21:04:37 2013
New Revision: 1450421
URL: http://svn.apache.org/r1450421
Log:
Document unchecked suppression.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java
Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java?rev=1450421&r1=1450420&r2=1450421&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java (original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java Tue Feb 26 21:04:37 2013
@@ -457,11 +457,12 @@ public abstract class AbstractMapBag<E>
* a supertype of the runtime type of the elements in this list
* @throws NullPointerException if the specified array is null
*/
- @SuppressWarnings("unchecked")
public <T> T[] toArray(T[] array) {
final int size = size();
if (array.length < size) {
- array = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
+ @SuppressWarnings("unchecked") // safe as both are of type T
+ final T[] unchecked = (T[]) Array.newInstance(array.getClass().getComponentType(), size);
+ array = unchecked;
}
int i = 0;
@@ -469,7 +470,10 @@ public abstract class AbstractMapBag<E>
while (it.hasNext()) {
final E current = it.next();
for (int index = getCount(current); index > 0; index--) {
- array[i++] = (T) current;
+ // unsafe, will throw ArrayStoreException if types are not compatible, see javadoc
+ @SuppressWarnings("unchecked")
+ final T unchecked = (T) current;
+ array[i++] = unchecked;
}
}
while (i < array.length) {