You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Chen Guoping (Jira)" <ji...@apache.org> on 2019/11/27 07:23:00 UTC
[jira] [Commented] (COLLECTIONS-737) The test
FluentIterableTest.size should be splitted
[ https://issues.apache.org/jira/browse/COLLECTIONS-737?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16983231#comment-16983231 ]
Chen Guoping commented on COLLECTIONS-737:
------------------------------------------
hello Pengyu Nie, maybe the IteratorUtils.size at line 807 needs to add a check if iterable is null, can you fix it ?
/**
* Returns the number of elements contained in the given iterator.
* <p>
* A <code>null</code> or empty iterator returns \{@code 0}.
*
* @param iterable the iterable to check, may be null
* @return the number of elements contained in the iterable
*/
public static int size(final Iterable<?> iterable) {
{color:#FF0000}if (iterable instanceof Collection<?>) {{color}
return ((Collection<?>) iterable).size();
}
return IteratorUtils.size(emptyIteratorIfNull(iterable));
}
> The test FluentIterableTest.size should be splitted
> ---------------------------------------------------
>
> Key: COLLECTIONS-737
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-737
> Project: Commons Collections
> Issue Type: Test
> Components: Collection
> Reporter: Pengyu Nie
> Priority: Major
> Time Spent: 20m
> Remaining Estimate: 0h
>
> The first part of FluentIterableTest.size is not testing function
> FluentIterable.size (see code copied below). Actually,
> FluentIterable.size will not be invoked at all, because
> FluentIterable.of(null) will throw an NPE before that. This part
> should be extracted as a separate unit test like
> FluentIterableTest.ofNull.
> {code:java}
> try {
> FluentIterable.of((Iterable<?>) null).size();
> fail("expecting NullPointerException");
> } catch (final NullPointerException npe) {
> // expected
> }{code}
> I'll create a pull request for this issue.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)