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
- links to