You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "SHIN HWEI TAN (Created) (JIRA)" <ji...@apache.org> on 2011/10/26 22:27:32 UTC

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

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: 3.2, 3.1, 3.0, 2.1.1, 2.1
         Environment: Platform Independent
            Reporter: SHIN HWEI TAN
            Priority: Minor


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

        

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

Posted by "SHIN HWEI TAN (Updated) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-385?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

SHIN HWEI TAN updated COLLECTIONS-385:
--------------------------------------

    Priority: Major  (was: Minor)

I found the same problem for overloaded method CollectionUtils#public static void addAll(Collection collection,Iterator iterator) and CollectionUtils#public static void addAll(Collection collection,Enumeration enumeration)
                
> 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

        

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

Posted by "Gary D. Gregory (Commented) (JIRA)" <ji...@apache.org>.
    [ 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

        

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

Posted by "Thomas Neidhart (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COLLECTIONS-385?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Thomas Neidhart resolved COLLECTIONS-385.
-----------------------------------------

    Resolution: Not A Problem
    
> 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

        

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

Posted by "SHIN HWEI TAN (Commented) (JIRA)" <ji...@apache.org>.
    [ 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