You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Maximilian Cascone (Jira)" <ji...@apache.org> on 2021/11/30 19:52:00 UTC

[jira] [Commented] (GROOVY-7207) every() from DefaultGroovyMethods returns true for empty iterator/list

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

Maximilian Cascone commented on GROOVY-7207:
--------------------------------------------

[~dmahapatro] Can you please explain how this is expected behavior? How can an empty list be true in all cases?

> every() from DefaultGroovyMethods returns true for empty iterator/list
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-7207
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7207
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.3.8, 2.4.0-beta-4
>            Reporter: Dhiraj Mahapatro
>            Priority: Major
>
> {code:java}
> assert [].every()
> assert [].every { it }
> assert [].every { it > 1 }
> {code}
> Is this an expected behavior? In all the variants of {{every()}} in {{DefaultGroovyMethods}} the logic is simlar to
> {code:java}
> BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
> for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
>     if (!bcw.call(iter.next())) {
>         return false;
>     }
> }
> return true;
> {code}
> So it defaults to true if {{!iter.hasNext()}}. Is this acceptable? Shouldn't it falsify based on empty List fails Groovy Truth?



--
This message was sent by Atlassian Jira
(v8.20.1#820001)