commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Tripodi <simonetrip...@apache.org>
Subject Re: svn commit: r1449929 - /commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/bag/AbstractMapBag.java
Date Tue, 26 Feb 2013 10:27:52 GMT
> it is not safe, and it will throw an ArrayStoreException in this case,
> which is documented in the throws clause.
>

OK I just read the commit, unless it is documented it is fine for me

-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/


On Tue, Feb 26, 2013 at 8:35 AM, Thomas Neidhart
<thomas.neidhart@gmail.com> wrote:
> On 02/26/2013 07:57 AM, Simone Tripodi wrote:
>> Hi Thomas,
>>
>>> +    @SuppressWarnings("unchecked")
>>>      public <T> T[] toArray(T[] array) {
>>>          final int size = size();
>>>          if (array.length < size) {
>>> -            // This is safe, both are type T
>>>              array = (T[]) Array.newInstance(array.getClass().getComponentType(),
size);
>>>          }
>>>
>>> @@ -466,7 +469,6 @@ public abstract class AbstractMapBag<E>
>>>          while (it.hasNext()) {
>>>              final E current = it.next();
>>>              for (int index = getCount(current); index > 0; index--) {
>>> -                // TODO this is unsafe
>>>                  array[i++] = (T) current;
>>>              }
>>>          }
>>>
>>
>> it is a good practice here commenting why the unchecked warning can be
>> suppressed - it will definitively help also future maintainers :)
>
> it is not safe, and it will throw an ArrayStoreException in this case,
> which is documented in the throws clause.
>
> This is the same behavior as with all java.util collections.
>
> Thomas
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message