[ 
https://issues.apache.org/jira/browse/COLLECTIONS-740?focusedWorklogId=353996&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-353996
 ]

ASF GitHub Bot logged work on COLLECTIONS-740:
----------------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Dec/19 01:58
            Start Date: 05/Dec/19 01:58
    Worklog Time Spent: 10m 
      Work Description: dota17 commented on pull request #124: 
[COLLECTIONS-740] Add missing @throws comment for 
SwitchTransformer.switchTransformer.
URL: 
https://github.com/apache/commons-collections/pull/124#discussion_r354077393
 
 

 ##########
 File path: 
src/main/java/org/apache/commons/collections4/functors/SwitchTransformer.java
 ##########
 @@ -51,6 +51,7 @@
      * @return the <code>chained</code> transformer
      * @throws NullPointerException if array is null
      * @throws NullPointerException if any element in the array is null
+     * @throws IllegalArgumentException if predicate and transformer arrays do 
not have the same size
 
 Review comment:
   maybe it's better to be the same as TransformerUtils line 317
   ` @throws IllegalArgumentException if the arrays have different sizes`
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

            Worklog Id:     (was: 353996)
    Remaining Estimate: 0h
            Time Spent: 10m

> Missing @throws comment in SwitchTransformer.switchTransformer
> --------------------------------------------------------------
>
>                 Key: COLLECTIONS-740
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-740
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Functor
>            Reporter: Pengyu Nie
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> SwitchTransformer.switchTransformer could throw IllegalArgumentException if 
> predicate and transformer arrays have different lengths, but that's not 
> described in Javadoc.  See the method below, the exception may happen in the 
> first if statement:
> {code:java}
> /**
>  * Factory method that performs validation and copies the parameter arrays.
>  *
>  * @param <I>  the input type
>  * @param <O>  the output type
>  * @param predicates  array of predicates, cloned, no nulls
>  * @param transformers  matching array of transformers, cloned, no nulls
>  * @param defaultTransformer  the transformer to use if no match, null means 
> return null
>  * @return the <code>chained</code> transformer
>  * @throws NullPointerException if array is null
>  * @throws NullPointerException if any element in the array is null
>  * @throws IllegalAccessException if predicate and transformer arrays do not 
> have the same size
>  */
> @SuppressWarnings("unchecked")
> public static <I, O> Transformer<I, O> switchTransformer(final Predicate<? 
> super I>[] predicates,
>         final Transformer<? super I, ? extends O>[] transformers,
>         final Transformer<? super I, ? extends O> defaultTransformer) {
>     FunctorUtils.validate(predicates);
>     FunctorUtils.validate(transformers);
>     if (predicates.length != transformers.length) {
>         throw new IllegalArgumentException("The predicate and transformer 
> arrays must be the same size");
>     }
>     if (predicates.length == 0) {
>         return (Transformer<I, O>) (defaultTransformer == null ? 
> ConstantTransformer.<I, O>nullTransformer() :
>                                                                  
> defaultTransformer);
>     }
>     return new SwitchTransformer<>(predicates, transformers, 
> defaultTransformer);
> }
> {code}
> I'll submit a PR to add the missing @throws documentation.



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

Reply via email to