Venkatesh-Prasad Ranganath created GROOVY-8537:

             Summary: GroovyCollections.combinations(Iterable) exhibits 
incorrect asymmetric behavior
                 Key: GROOVY-8537
             Project: Groovy
          Issue Type: Bug
          Components: groovy-jdk
    Affects Versions: 2.4.15
            Reporter: Venkatesh-Prasad Ranganath

h4. *Issue*

When GroovyCollections.combinations() is invoked on a collection of iterables 
with at least one empty iterable, the expected return value is an empty list of 

Instead, in version 2.4.15 (and I am guessing in earlier versions at least 
since 2.2.0), the return value of combinations() is sensitive to the order of 
iterables in the input collection.  Here are two instances of such behavior.
h4. Repro

{{groovy:000> assert [[1,3], []].combinations() == [[], [1,3]].combinations()}}
{{ERROR org.codehaus.groovy.runtime.powerassert.PowerAssertionError:}}
{{assert [[1,3], []].combinations() == [[], [1,3]].combinations()}}
{{                   |              |              |}}
{{                   []             false          [[1], [3]]}}


{{groovy:000> assert [[1,3], [2], []].combinations() == [[1,3], [], 
{{ERROR org.codehaus.groovy.runtime.powerassert.PowerAssertionError:}}
{{assert [[1,3], [2], []].combinations() == [[1,3], [], [2]].combinations()}}
{{                        |              |                   |}}
{{                        []             false               [[2]]}}
h4. *Fix*

A simple short-circuiting check at the start of combinations(Iterable) method 
to return an empty list of combination if any of the input iterables are empty 
should fix the problem.

This message was sent by Atlassian JIRA

Reply via email to