Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-740

Missing @throws comment in SwitchTransformer.switchTransformer

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.5.0-M1
    • Functor
    • None

    Description

      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:

      /**
       * 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);
      }
      

      I'll submit a PR to add the missing @throws documentation.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              prodigysov Pengyu Nie
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 0.5h
                  0.5h