You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Commented) (JIRA)" <ji...@apache.org> on 2011/10/29 23:13:32 UTC

[jira] [Commented] (COLLECTIONS-385) Inconsistent Javadoc comment and code in addAll(Collection, Object[]) in org.apache.commons.collections.CollectionUtils

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

Gary D. Gregory commented on COLLECTIONS-385:
---------------------------------------------

I do not think this applies to trunk.
                
> 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