Author: tn
Date: Tue Jan 22 16:08:48 2013
New Revision: 1437018
URL: http://svn.apache.org/viewvc?rev=1437018&view=rev
Log:
Move input parameter cloning from factory method to the ctor to prevent
findbugs warning.
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/InstantiateFactory.java
Modified:
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/InstantiateFactory.java
URL:
http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/InstantiateFactory.java?rev=1437018&r1=1437017&r2=1437018&view=diff
==============================================================================
---
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/InstantiateFactory.java
(original)
+++
commons/proper/collections/trunk/src/main/java/org/apache/commons/collections/functors/InstantiateFactory.java
Tue Jan 22 16:08:48 2013
@@ -48,11 +48,12 @@ public class InstantiateFactory<T> imple
*
* @param <T> the type the factory creates
* @param classToInstantiate the class to instantiate, not null
- * @param paramTypes the constructor parameter types
- * @param args the constructor arguments
+ * @param paramTypes the constructor parameter types, cloned
+ * @param args the constructor arguments, cloned
* @return a new instantiate factory
*/
- public static <T> Factory<T> instantiateFactory(final Class<T>
classToInstantiate, Class<?>[] paramTypes,
+ public static <T> Factory<T> instantiateFactory(final Class<T>
classToInstantiate,
+ Class<?>[] paramTypes,
Object[] args) {
if (classToInstantiate == null) {
throw new IllegalArgumentException("Class to instantiate must not
be null");
@@ -66,8 +67,6 @@ public class InstantiateFactory<T> imple
if (paramTypes == null || paramTypes.length == 0) {
return new InstantiateFactory<T>(classToInstantiate);
}
- paramTypes = paramTypes.clone();
- args = args.clone();
return new InstantiateFactory<T>(classToInstantiate, paramTypes, args);
}
@@ -90,14 +89,14 @@ public class InstantiateFactory<T> imple
* Use <code>getInstance</code> if you want that.
*
* @param classToInstantiate the class to instantiate
- * @param paramTypes the constructor parameter types, not cloned
- * @param args the constructor arguments, not cloned
+ * @param paramTypes the constructor parameter types, cloned
+ * @param args the constructor arguments, cloned
*/
public InstantiateFactory(final Class<T> classToInstantiate, final
Class<?>[] paramTypes, final Object[] args) {
super();
iClassToInstantiate = classToInstantiate;
- iParamTypes = paramTypes;
- iArgs = args;
+ iParamTypes = paramTypes.clone();
+ iArgs = args.clone();
findConstructor();
}
@@ -107,7 +106,6 @@ public class InstantiateFactory<T> imple
private void findConstructor() {
try {
iConstructor = iClassToInstantiate.getConstructor(iParamTypes);
-
} catch (final NoSuchMethodException ex) {
throw new IllegalArgumentException("InstantiateFactory: The
constructor must exist and be public ");
}