diff --git a/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java b/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java index ca415d63b..2e4436a29 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java +++ b/src/main/java/org/apache/commons/collections4/functors/ChainedClosure.java @@ -49,7 +49,7 @@ public class ChainedClosure implements Closure, Serializable { if (closures.length == 0) { return NOPClosure.nopClosure(); } - return new ChainedClosure(FunctorUtils.copy(closures)); + return new ChainedClosure(closures); } /** @@ -78,18 +78,28 @@ public class ChainedClosure implements Closure, Serializable { cmds[i++] = closure; } FunctorUtils.validate(cmds); - return new ChainedClosure(cmds); + return new ChainedClosure(false, cmds); + } + + /** + * Hidden constructor for the use by the static factory methods. + * + * @param clone if {@code true} the input argument will be cloned + * @param closures the closures to chain, no nulls + */ + private ChainedClosure(final boolean clone, final Closure... closures) { + super(); + iClosures = clone ? FunctorUtils.copy(closures) : closures; } /** * Constructor that performs no validation. * Use chainedClosure if you want that. * - * @param closures the closures to chain, not copied, no nulls + * @param closures the closures to chain, copied, no nulls */ - public ChainedClosure(final Closure[] closures) { - super(); - iClosures = closures; + public ChainedClosure(final Closure... closures) { + this(true, closures); } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java b/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java index 5f270538c..045a80644 100644 --- a/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/ChainedTransformer.java @@ -52,7 +52,7 @@ public class ChainedTransformer implements Transformer, Serializable { if (transformers.length == 0) { return NOPTransformer.nopTransformer(); } - return new ChainedTransformer(FunctorUtils.copy(transformers)); + return new ChainedTransformer(transformers); } /** @@ -77,18 +77,28 @@ public class ChainedTransformer implements Transformer, Serializable { // convert to array like this to guarantee iterator() ordering final Transformer[] cmds = transformers.toArray(new Transformer[transformers.size()]); FunctorUtils.validate(cmds); - return new ChainedTransformer(cmds); + return new ChainedTransformer(false, cmds); + } + + /** + * Hidden constructor for the use by the static factory methods. + * + * @param clone if {@code true} the input argument will be cloned + * @param transformers the transformers to chain, not copied, no nulls + */ + private ChainedTransformer(final boolean clone, final Transformer[] transformers) { + super(); + iTransformers = clone ? FunctorUtils.copy(transformers) : transformers; } /** * Constructor that performs no validation. * Use chainedTransformer if you want that. * - * @param transformers the transformers to chain, not copied, no nulls + * @param transformers the transformers to chain, copied, no nulls */ - public ChainedTransformer(final Transformer[] transformers) { - super(); - iTransformers = transformers; + public ChainedTransformer(final Transformer... transformers) { + this(true, transformers); } /**