[ 
https://issues.apache.org/jira/browse/COLLECTIONS-385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13139506#comment-13139506
 ] 

SHIN HWEI TAN commented on COLLECTIONS-385:
-------------------------------------------

Yes, the trunk currently have:

           /**
             * Adds all elements in the iteration to the given collection.
             *
             * @param collection
             *            the collection to add to, must not be null
             * @param iterator
             *            the iterator of elements to add, must not be null
             * @return a boolean indicating whether the collection has changed 
or not.
             * @throws NullPointerException
             *             if the collection or iterator is null
             */
            public static <C> boolean addAll(Collection<C> collection, 
Iterator<? extends C> iterator) {
                boolean changed = false;
                while (iterator.hasNext()) {
                    changed |= collection.add(iterator.next());
                }
                return changed;
            }

           /**
             * Adds all elements in the array to the given collection.
             *
             * @param collection
             *            the collection to add to, must not be null
             * @param elements
             *            the array of elements to add, must not be null
             * @throws NullPointerException
             *             if the collection or array is null
             */
            public static <C> boolean addAll(Collection<C> collection, C[] 
elements) {
                 ............
            }

           /**
             * Adds all elements in the iteration to the given collection.
             *
             * @param collection
             *            the collection to add to, must not be null
             * @param iterator
             *            the iterator of elements to add, must not be null
             * @return a boolean indicating whether the collection has changed 
or not.
             * @throws NullPointerException
             *             if the collection or iterator is null
             */
            public static <C> boolean addAll(Collection<C> collection, 
Iterator<? extends C> iterator) {

           /**
             * Adds all elements in the iteration to the given collection.
             *
             * @param collection
             *            the collection to add to, must not be null
             * @param iterator
             *            the iterator of elements to add, must not be null
             * @return a boolean indicating whether the collection has changed 
or not.
             * @throws NullPointerException
             *             if the collection or iterator is null
             */
            public static <C> boolean addAll(Collection<C> collection, 
Iterator<? extends C> iterator) {
                    .....
            }

When called with an empty iterator/elements and a null collection (i.e., 
ArrayList al=new ArrayList(); addAll((Collection)null, new al.iterator())"), 
the method still executes normally without throwing any exception.
                
> Inconsistent Javadoc comment and code in addAll(Collection, Object[]) in 
> org.apache.commons.collections.CollectionUtils
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-385
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-385
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Collection
>    Affects Versions: 2.1, 2.1.1, 3.0, 3.1, 3.2
>         Environment: Platform Independent
>            Reporter: SHIN HWEI TAN
>              Labels: javadoc, nullpointerexception
>   Original Estimate: 5m
>  Remaining Estimate: 5m
>
> The Javadoc comment below states that the method "throws NullPointerException 
> if the collection or array is null". 
>     /** 
>      * Adds all elements in the array to the given collection.
>      * 
>      * @param collection  the collection to add to, must not be null
>      * @param elements  the array of elements to add, must not be null
>      * @throws NullPointerException if the collection or array is null
>      */
>     public static void addAll(Collection collection, Object[] elements) {
>         for (int i = 0, size = elements.length; i < size; i++) {
>             collection.add(elements[i]);
>         }
>     }    
> However, when called with an empty array and a null collection (i.e., 
> "addAll((Collection)null, new Object[])"), the method executes normally 
> without throwing any exception.
> Suggested Fixes:
> 1. Add code "if (collection == null) throw NullPointerException();" at the 
> beginning of the method body.
> or
> 2. Remove "@throws NullPointerException if the collection or array is null" 
> from the Javadoc.
> or
> 3. Change "@throws NullPointerException if the collection or array is null" 
> to "@throws NullPointerException if the array is null or (the array is 
> non-empty and the collection is null)".

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to