diff --git a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java index a1a93804c..4961f3234 100644 --- a/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/InstantiateTransformer.java @@ -60,7 +60,8 @@ public class InstantiateTransformer implements Transformer * @param args the constructor arguments * @return an instantiate transformer */ - public static Transformer, T> instantiateTransformer(Class[] paramTypes, Object[] args) { + public static Transformer, T> instantiateTransformer(final Class[] paramTypes, + final Object[] args) { if (((paramTypes == null) && (args != null)) || ((paramTypes != null) && (args == null)) || ((paramTypes != null) && (args != null) && (paramTypes.length != args.length))) { @@ -93,8 +94,8 @@ public class InstantiateTransformer implements Transformer */ public InstantiateTransformer(final Class[] paramTypes, final Object[] args) { super(); - iParamTypes = paramTypes.clone(); - iArgs = args.clone(); + iParamTypes = paramTypes != null ? paramTypes.clone() : null; + iArgs = args != null ? args.clone() : null; } /** diff --git a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java index 49686d9ca..2466ea912 100644 --- a/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java +++ b/src/main/java/org/apache/commons/collections4/functors/InvokerTransformer.java @@ -67,8 +67,8 @@ public class InvokerTransformer implements Transformer, Serializable * @param args the arguments to pass to the method * @return an invoker transformer */ - public static Transformer invokerTransformer(final String methodName, Class[] paramTypes, - Object[] args) { + public static Transformer invokerTransformer(final String methodName, final Class[] paramTypes, + final Object[] args) { if (methodName == null) { throw new IllegalArgumentException("The method to invoke must not be null"); } @@ -80,8 +80,6 @@ public class InvokerTransformer implements Transformer, Serializable if (paramTypes == null || paramTypes.length == 0) { return new InvokerTransformer(methodName); } else { - paramTypes = paramTypes.clone(); - args = args.clone(); return new InvokerTransformer(methodName, paramTypes, args); } } @@ -101,16 +99,18 @@ public class InvokerTransformer implements Transformer, Serializable /** * Constructor that performs no validation. * Use invokerTransformer if you want that. + *

+ * Note: from 4.0, the input parameters will be cloned * * @param methodName the method to call - * @param paramTypes the constructor parameter types, not cloned - * @param args the constructor arguments, not cloned + * @param paramTypes the constructor parameter types + * @param args the constructor arguments */ public InvokerTransformer(final String methodName, final Class[] paramTypes, final Object[] args) { super(); iMethodName = methodName; - iParamTypes = paramTypes; - iArgs = args; + iParamTypes = paramTypes != null ? paramTypes.clone() : null; + iArgs = args != null ? args.clone() : null; } /**