You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Elia Bertolina (Jira)" <ji...@apache.org> on 2022/05/23 13:25:00 UTC

[jira] [Created] (COLLECTIONS-815) Multiple ClosureUtils methods not throwing proper IllegalArgumentException

Elia Bertolina created COLLECTIONS-815:
------------------------------------------

             Summary: Multiple ClosureUtils methods not throwing proper IllegalArgumentException
                 Key: COLLECTIONS-815
                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-815
             Project: Commons Collections
          Issue Type: Bug
    Affects Versions: 4.4
            Reporter: Elia Bertolina


3 methods from ClosureUtils fails to throw an IllegalArgumentException when at least one of their parameters is empty.

The methods and the test cases that highlight the issue are the following:

ClosureUtils.chainedClosure (Collection<? extends Closure<? super E>> closures) 
{code:java}
public class ClosureUtils_failure_Test_1 {    
    public void test() throws Throwable {
        LinkedList<Closure<Object>> linkedList = 
        new LinkedList<Closure<Object>>();
        try {            
           Closure<Object> closure = 
           ClosureUtils.chainedClosure(
           (Collection<? extends Closure<? super Object>>) linkedList);
           org.junit.Assert.fail();
        } catch (java.lang.IllegalArgumentException e) {
           //Exception caught and test successful 
        }    
    }
} {code}
ClosureUtils.switchMapClosure (Map<? extends E, Closure<E>> objectsAndClosures)
{code:java}
public class ClosureUtils_failure_Test_2 {
    public void test() throws Throwable {
        HashMap<Object, Closure<Object>> hashMap = 
        new HashMap<Object, Closure<Object>>();
        try {            
           Closure<Object> closure =  
           ClosureUtils.switchMapClosure(
           (Map<?, Closure<Object>>) hashMap);
           org.junit.Assert.fail();
        } catch (java.lang.IllegalArgumentException e) {
           //Exception caught and test successful
        }    
    }
} {code}
ClosureUtils.switchClosure (Map<Predicate<E>, Closure<E>> predicatesAndClosures)
{code:java}
public class ClosureUtils_failure_Test_3 {
    public void test() throws Throwable {
        HashMap<Predicate<Object>, Closure<Object>> hashMap = 
        new HashMap<>();
        try {
            Closure<Object> closure = 
            ClosureUtils.switchClosure(hashMap);
            org.junit.Assert.fail();
        } catch (java.lang.IllegalArgumentException e) {
            //Exception caught and test successful
        }    
    }
} {code}
All the above test cases fail to catch an IllegalArgumentException.

I was taking a look at the upcoming version currently in development and all 3 methods seems to return an empty NOPClosure, without throwing any IllegalArgumentException. Is the code wrong or the documentation simply out of date?

 



--
This message was sent by Atlassian Jira
(v8.20.7#820007)