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

Chen Guoping edited comment on COLLECTIONS-738 at 11/30/19 1:52 AM:
--------------------------------------------------------------------

Hi Pengyu Nie: 

  I recommend updating the javadoc documentation synchronously stating that 
predicate must not be null in the IterableUtils.

IterableUtils line 609  : may -> must


{code:java}
 /** Finds the first element in the given iterable which matches the given 
predicate. <p> A <code>null</code> or empty iterator returns null.
 * @param <E> the element type @param iterable the iterable to search, may be 
null @param predicate the predicate to use, may not be null @return the first 
element of the iterable which matches the predicate or null if none could be 
found @throws NullPointerException if predicate is null */ public static <E> E 
find(final Iterable<E> iterable, final Predicate<? super E> predicate) 
 {code}
 * IterableUtils line 1265 : may -> must


{code:java}
/** Finds the first element in the given iterator which matches the given 
predicate. <p> A <code>null</code> or empty iterator returns null.
 * @param <E> the element type @param iterator the iterator to search, may be 
null @param predicate the predicate to use, may not be null @return the first 
element of the iterator which matches the predicate or null if none could be 
found @throws NullPointerException if predicate is null @since 4.1 */ public 
static <E> E find(final Iterator<E> iterator, final Predicate<? super E> 
predicate) {code}


was (Author: guoping):
Hi Pengyu Nie: 

  I recommend updating the javadoc documentation synchronously stating that 
predicate must not be null in the IterableUtils.

IterableUtils line 609  : may -> must
/**
 * Finds the first element in the given iterable which matches the given 
predicate.
 * <p>
 * A <code>null</code> or empty iterator returns null.
 *
 * @param <E> the element type
 * @param iterable  the iterable to search, may be null
 * @param predicate  the predicate to use, may not be null
 * @return the first element of the iterable which matches the predicate or 
null if none could be found
 * @throws NullPointerException if predicate is null
 */
public static <E> E find(final Iterable<E> iterable, final Predicate<? super E> 
predicate) {
IterableUtils line 1265 : may -> must
/**
 * Finds the first element in the given iterator which matches the given 
predicate.
 * <p>
 * A <code>null</code> or empty iterator returns null.
 *
 * @param <E> the element type
 * @param iterator  the iterator to search, may be null
 * @param predicate  the predicate to use, {color:#FF0000}may{color} not be null
 * @return the first element of the iterator which matches the predicate or 
null if none could be found
 * @throws NullPointerException if predicate is null
 * @since 4.1
 */
public static <E> E find(final Iterator<E> iterator, final Predicate<? super E> 
predicate) {

> The last assertNull in IterableUtilsTest.find is redundant
> ----------------------------------------------------------
>
>                 Key: COLLECTIONS-738
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-738
>             Project: Commons Collections
>          Issue Type: Test
>          Components: Iterator
>            Reporter: Pengyu Nie
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> The last assertNull in IterableUtilsTest.find (line 277, as shown
>  below), is redundant and confusing; it will not be invoked because
>  IterableUtils.find(*, null) should not return any value but just throw
>  NullPointerException. I will make a PR to clarify this.
> {code:java}
> try {
>     assertNull(IterableUtils.find(iterableA, null));
>     fail("expecting NullPointerException");
> } catch (final NullPointerException npe) {
>     // expected
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to